var CunhuoNavCtrl = ['$scope', '$rootScope',
    function ($scope, $rootScope) {
        $scope.menu_list = [{
                name: $rootScope.language.TIPS_INVOICING_NAVIGATION,
                url: "#/cunhuo/invoicing_nav",
                id: "invoicing_nav",
                type: "2",
                show: '1'
            }, {
                name: $rootScope.language.TIP_CUNHUO_GOODS,
                url: "",
                id: "",
                type: "1",
                show: '1'
            }, {
                name: $rootScope.language.TIP_CUNHUO_GOODS_ASK,
                url: "#cunhuo/peihuo_list",
                id: "peihuo_list",
                type: "2",
                show: $rootScope.purview['\/CunhuoPeihuoListCtrl'].show
            }, {
                name: $rootScope.language.TIPS_INVENTORY_PUT_STORE_ORDER,
                url: "#cunhuo/ruku",
                id: "ruku_list",
                type: "2",
                show: $rootScope.purview['\/CunhuoRukuListCtrl'].show
            }, {
                name: $rootScope.language.TIPS_INVENTORY_BACK_STOCK,
                url: "#cunhuo/tuiku_list",
                id: "tuiku_list",
                type: "2",
                show: $rootScope.purview['\/CunhuoTuikuListCtrl'].show
            }, {
                name: $rootScope.language.TIPS_INVENTORY_OUT_STORE_ORDER,
                url: "#cunhuo/chuku",
                id: "chuku_list",
                type: "2",
                show: $rootScope.purview['\/cunhuo\/chuku'].show
            },
            {
                name: $rootScope.language.TIPS_INVENTORY_ALLOT,
                url: "",
                id: "",
                type: "1",
                show: '1'
            },
            {
                name: $rootScope.language.TIPS_INVENTORY_ALLOT_ORDER_ASK,
                url: "#cunhuo/diaobo_list",
                id: "diaobo_list",
                type: "2",
                show: $rootScope.purview['\/CunhuoDiaoboListCtrl'].show
            }, {
                name: $rootScope.language.TIPS_INVENTORY_EXPORT_ORDER,
                url: "#cunhuo/diaochu_list",
                id: "diaochu_list",
                type: "2",
                show: $rootScope.purview['\/CunhuoDiaoChuDetailCtrl'].show
            }, {
                name: $rootScope.language.TIPS_INVENTORY_FOLD_ORDER,
                url: "#cunhuo/diaoru_list",
                id: "diaoru_list",
                type: "2",
                show: $rootScope.purview['\/CunhuoDiaoboListCtrl'].show
            }, {
                name: $rootScope.language.TIPS_INVENTORY_CHECK,
                url: "",
                id: "",
                type: "1",
                show: '1'
            }, {
                name: $rootScope.language.TIPS_INVENTORY_CHECK_ORDER_TASK,
                url: "#cunhuo/pandianTask_list",
                id: "pandianTask_list",
                type: "2",
                show: $rootScope.purview['\/cunhuo\/pandianTask_list'].show
            }, {
                name: $rootScope.language.TIPS_INVENTORY_CHECK_ORDER,
                url: "#cunhuo/pandian_list",
                id: "pandian_list",
                type: "2",
                show: $rootScope.purview['\/CunhuoPanDianListCtrl'].show
            }, {
                name: $rootScope.language.TIPS_INVENTORY_ADJUST_MEMO,
                url: "#cunhuo/adjust_list",
                id: "adjust_list",
                type: "2",
                show: $rootScope.purview['\/CunhuoPanDianAdjustCtrl'].show
            }, {
                name: $rootScope.language.TIPS_FINISHED,
                url: "",
                id: "",
                type: "1",
                show: '1'
            }, {
                name: $rootScope.language.MENU_CUNHUO_LSXHD,
                url: "#cunhuo/sale_list",
                id: "sale_list",
                type: "2",
                show: $rootScope.purview['\/Cunhuo\/finished_sale'].show
            }, {
                name: $rootScope.language.MENU_CUNHUO_LSTHD,
                url: "#cunhuo/return_list",
                id: "return_list",
                type: "2",
                show: $rootScope.purview['\/Cunhuo\/Finished_return'].show
            }];

    }];

//进销存导航
var InvoicingNavCtrl = ['$scope', '$rootScope', function ($scope, $rootScope) {
        $scope.curr = 'invoicing_nav';
    }];


//配货单
var CunhuoPeihuoListCtrl = ['$scope', '$location', '$rootScope', 'ngDialog', 'dbSelect', 'timeStamp2String', 'yaoHuo', 'PosUser', 'ShopSetCheck',
    function ($scope, $location, $rootScope, ngDialog, dbSelect, timeStamp2String, yaoHuo, PosUser, ShopSetCheck) {
        ShopSetCheck();
        //检查店铺是否绑定
        $scope.curr = "peihuo_list";
        $scope.filter = {};
        //查询条件
        $scope.filter.record_code = '';
        $scope.filter.record_time_start = '';
        $scope.filter.record_time_end = '';
        var window_id = 0;

        //窗口id
        //滑动事件加载锁========================================
        //往下点击获取更多
        $scope.scoll = {};
        //滚动加载器
        $scope.scoll.busy = false;
        $scope.scoll.nextpage = function () {
            if ($scope.scoll.busy)
                return;
            baison_app.api.toast({
                msg: $rootScope.language.COMMON_LOADING
            });
            $scope.scoll.busy = true;
            var param = {};
            param.is_pre = 1;
            param.shop_code = $rootScope.current_shop.ShopCode;
            if ($scope.peihuo_list.length > 0) {
                param.day = $scope.peihuo_list[$scope.peihuo_list.length - 1]['key'];
            }
            yaoHuo.peihuo_search_api(param).then(function (ret) {
                if (ret.data.status == 1) {
                    for (i in ret.data.data) {
                        $scope.peihuo_list.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.scoll.busy = false;
                } else if (ret.data.status == -1) {
                    baison_app.api.toast({
                        msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
                    });
                    $scope.is_show = "";
                }
            });
        };
        //私有方法===============================================================
        //从服务器搜索
        var search_api = function (filter) {
            yaoHuo.peihuo_search_api(filter).then(function (ret) {
                if (ret.data.status != 1) {
                    $scope.is_show = "";
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language[ret.data.code]
                    });
                    return;
                } else if (ret.data.status == 1) {
                    $scope.is_show = "true";
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                        //第一个日期的
                    }
                    $scope.peihuo_list = data;
                }
            }).catch(function (err) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
        };
        //默认查找在线（服务器搜索）
        search_api({
            shop_code: $rootScope.current_shop.ShopCode
        });
        //要货申请（配货单）查询
        $scope.search = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
            window_id = ngDialog.open({closeByDocument: false,
                trapFocus: false,
                template: './html/cunhuo/peihuo/peihuo_select.html',
                disableAnimation: true,
                scope: $scope,
                //                closeByDocument: false
            });
        };
        //重置按钮
        $scope.clear = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
        };
        //弹框处理================================================================
        //配货单查询（按时间查询）
        $scope.peihuo_select = function (filterData) {
            if (filterData.record_time_start == '' || filterData.record_time_end == '') {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME
                });
                return;
            }
            if (filterData.record_time_start > filterData.record_time_end) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME_LIMIT
                });
                return;
            }
            yaoHuo.peihuo_select(filterData).then(function (ret) {
                if (ret.data.status != 1) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language[ret.data.code]
                    });
                    return;
                } else if (ret.data.status == 1) {
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                        //第一个日期的
                    }
                    $scope.peihuo_list = data;
                }
            }).catch(function (err) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
            ngDialog.close(window_id);
        };

    }];

//配货列表细节
var CunhuoPeihuoDetailCtrl = ['$scope', '$location', 'Print', '$routeParams', 'yaoHuo', 'BaseGoods', 'timeStamp2String',
    function ($scope, $location, Print, $routeParams, yaoHuo, BaseGoods, timeStamp2String) {
        $scope.curr = "peihuo_list";
        var filter = {};
        //查询条件
        filter.record_code = $routeParams.record_code;
        yaoHuo.peihuo_list_detail_search_by_code(filter).then(function (ret) {
            $scope.peihuo_list_detail = ret.data.data;
            $scope.peihuo_list_detail.record.record_time = timeStamp2String(ret.data.data.record.record_time, 'date');
            $.each($scope.peihuo_list_detail.record_detail, function (i, n) {
                $scope.peihuo_list_detail.record_detail[i]['GoodsName'] = '';
                if (n.goods_name != '' && n.goods_name !== undefined) {
                    $scope.peihuo_list_detail.record_detail[i]['GoodsName'] = n.goods_name;
                } else {
                    BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
                        $scope.peihuo_list_detail.record_detail[i]['GoodsName'] = ret.GoodsName;
                    });
                }
            });
        });
        //关闭
        $scope.come_back = function () {
            $location.path('/cunhuo/peihuo_list');
        };
        //added by lqx maowei on 20170116 打印配货申请详细
        $scope.to_print_peihuodetail = function () {
            var filter = {};
            //added by lqx maowei on 20170116 查询条件
            filter.record_code = $routeParams.record_code;
            yaoHuo.peihuo_list_detail_search_by_code(filter).then(function (ret) {
                var peihuodetail = ret.data.data;
                    //added by lqx maowei on 20170116 根据返回数据进行打印
                    Print.peihuodetail_print('', peihuodetail);
            });
        };
    }];

//新增配货单(空白要货单)
var CunhuoPeihuoAddCtrl = ['$scope', '$rootScope', '$location', '$routeParams', 'dbSelect', 'yaoHuo', 'timeStamp2String', 'PosUser','ThirdDev',
    function ($scope, $rootScope, $location, $routeParams, dbSelect, yaoHuo, timeStamp2String, PosUser,ThirdDev) {
        $scope.curr = "peihuo_list";
        $scope.is_lqx = ThirdDev.is_lqx();
        //新增配货单:营业员选择、配货类型选择、仓库
        $scope.peihuo_add_filter = {};
        //配货类型选择
        $scope.peihuo_add_filter.allocate_type_option = [];
        //营业员选择
        $scope.peihuo_add_filter.user_code_option = [];
        //仓库选择
        $scope.peihuo_add_filter.store_code_option = [];
        //0:林清轩
        if (ThirdDev.is_lqx()) {  //$rootScope.purview['\/cunhuo\/chuku'].show == 0
            $scope.peihuo_add_filter.ck = "总仓";
        }
        //营业员下拉
        var user_filter = {
            'ShopCode': $rootScope.current_shop.ShopCode,
            'UserStatus': 1
        };
        //单据配货类型下拉
        var record_type = {
            'record_type_property': 6
        };
        //仓库下拉
        var ck_filter = {
            'status': 1
        };
        //生成单据编号
        $scope.peihuo_add_filter.record_code = yaoHuo.create_fast_bill_sn('allocate_order');
        //日期
        $scope.peihuo_add_filter.record_time = timeStamp2String(0, 'date');
        //营业员下拉菜单获取
        PosUser.get_list_by_cond(user_filter).then(function (ret) {

            $scope.peihuo_add_filter.user_code_option = ret;

        });
        //配货类型下拉
        yaoHuo.record_type_list(record_type).then(function (ret) {
            if (ret.length == 1) {
                $scope.peihuo_add_filter.record_type_code = ret[0].record_type_code;
                $scope.peihuo_add_filter.record_type_name = ret[0].record_type_name;
            }
            $scope.peihuo_add_filter.allocate_type_option = ret;
        });
        //1:ipos
        if (!ThirdDev.is_lqx()){  //$rootScope.purview['\/cunhuo\/chuku'].show == 1
         	//仓库下拉
	        yaoHuo.select_storage_list(ck_filter).then(function (ret) {
	            if (ret.length == 1) {
	                $scope.peihuo_add_filter.store_code = ret[0].store_code;
	                $scope.peihuo_add_filter.store_name = ret[0].store_name;
	            }
	            $scope.peihuo_add_filter.store_code_option = ret;
	        });
         }
        
        //保存到本地,跳转到配货单详情
        $scope.save_local = function (data) {
            //林清轩
             if (ThirdDev.is_lqx()) {//$rootScope.purview['\/cunhuo\/chuku'].show == 0
                if (data.record_type_code === undefined || data.record_type_code == null || data.user_code === undefined || data.user_code == null) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_INFO_NEED
                    });
                    return false;
                }
            }else{
            	if (data.store_code === undefined || data.store_code == null || data.user_code === undefined || data.user_code == null || data.record_type_code === undefined || data.record_type_code == null) {
	                baison_app.api.toast({
	                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
	                    title: $rootScope.language.COMMON_TITLE_HINT,
	                    msg: $rootScope.language.TIPS_CUNHUO_INFO_NEED
	                });
	                return false;
	            }
            }
            //林清轩
            if (ThirdDev.is_lqx()) {//$rootScope.purview['\/cunhuo\/chuku'].show == 0
                  $rootScope.local_peihuo_record = yaoHuo.save_local(data);
	                $location.path('/cunhuo/peihuo_add_detail');
            }else{
            	var localData = yaoHuo.save_local(data);
	            yaoHuo.getStoreName_by_code(localData.store_code).then(function (response) {
	                localData.store_name = response[0].store_name;
	                $rootScope.local_peihuo_record = localData;
	                $location.path('/cunhuo/peihuo_add_detail');
	            });
            }
            
        };
        //重置按钮
        $scope.reset = function (data) {
            yaoHuo.select_storage_list(ck_filter).then(function (ret) {
                data.allocate_type = data.user_code = data.store_code = undefined;
                data.store_code = ret[0].store_code;
            });
        };

    }];

//新增配货单（建议要货）
var CunhuoPeihuoAddAdviseCtrl = ['$scope', '$rootScope', '$location', '$routeParams', 'dbSelect', 'yaoHuo', 'timeStamp2String', 'PosUser','ThirdDev',
    function ($scope, $rootScope, $location, $routeParams, dbSelect, yaoHuo, timeStamp2String, PosUser,ThirdDev) {
        $scope.curr = "peihuo_list";
        $scope.is_lqx = ThirdDev.is_lqx();
        //新增配货单:营业员选择、配货类型选择、仓库
        $scope.peihuo_add_filter = {};
        //配货类型选择
        $scope.peihuo_add_filter.allocate_type_option = [];
        //营业员选择
        $scope.peihuo_add_filter.user_code_option = [];
        //仓库选择
        $scope.peihuo_add_filter.store_code_option = [];
        
        //营业员下拉
        var user_filter = {
            'ShopCode': $rootScope.current_shop.ShopCode,
            'UserStatus': 1
        };
        //单据配货类型下拉
        var record_type = {
            'record_type_property': 6
        };
        //仓库下拉
        var ck_filter = {
            'status': 1
        };
        
        //0:林清轩
        if (ThirdDev.is_lqx()) {  //$rootScope.purview['\/cunhuo\/chuku'].show == 0
            $scope.peihuo_add_filter.ck = "总仓";
        }
        //生成单据编号
        $scope.peihuo_add_filter.record_code = yaoHuo.create_fast_bill_sn('allocate_order');
        //日期
        $scope.peihuo_add_filter.record_time = timeStamp2String(0, 'datetime');
        //营业员下拉菜单获取
        PosUser.get_list_by_cond(user_filter).then(function (ret) {
            $scope.peihuo_add_filter.user_code_option = ret;
            //一个导购员数组
        });
        //配货类型下拉
        yaoHuo.record_type_list(record_type).then(function (ret) {
            if (ret.length == 1) {
                $scope.peihuo_add_filter.record_type_code = ret[0].record_type_code;
                $scope.peihuo_add_filter.record_type_name = ret[0].record_type_name;
            }
            $scope.peihuo_add_filter.allocate_type_option = ret;
            //record_type_name
        });
        
         //ipos
        if (!ThirdDev.is_lqx()){  //$rootScope.purview['\/cunhuo\/chuku'].show == 1
	        //仓库下拉
	        yaoHuo.select_storage_list(ck_filter).then(function (ret) {
	            if (ret.length == 1) {
	                $scope.peihuo_add_filter.store_code = ret[0].store_code;
	                $scope.peihuo_add_filter.store_name = ret[0].store_name;
	            }
	            //$scope.peihuo_add_filter.store_code = ret[0].store_code;
	            $scope.peihuo_add_filter.store_code_option = ret;
	        });
         }
        
        //保存到本地,跳转到配货单详情
        $scope.save_local = function (data) {
             //林清轩
            if (ThirdDev.is_lqx()) { //$rootScope.purview['\/cunhuo\/chuku'].show == 0
                if (data.record_type_code === undefined || data.record_type_code == null || data.user_code === undefined || data.user_code == null) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_INFO_NEED
                    });
                    return false;
                }
            } else {
                if (data.store_code === undefined || data.store_code == null || data.user_code === undefined || data.user_code == null || data.record_type_code === undefined || data.record_type_code == null) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_INFO_NEED
                    });
                    return false;
                }
            }
			//林清轩
            if (ThirdDev.is_lqx()) {//$rootScope.purview['\/cunhuo\/chuku'].show == 0
                $rootScope.local_peihuo_record = yaoHuo.save_local(data);
                $location.path('/cunhuo/peihuo_add_advise_detail');
            } else {
                var localData = yaoHuo.save_local(data);
                yaoHuo.getStoreName_by_code(localData.store_code).then(function (response) {
                    localData.store_name = response[0].store_name;
                    $rootScope.local_peihuo_record = localData;
                    $location.path('/cunhuo/peihuo_add_advise_detail');
                });
            }

        };
        //重置按钮
        $scope.reset = function (data) {
            yaoHuo.select_storage_list(ck_filter).then(function (ret) {
                data.allocate_type = data.user_code = data.store_code = undefined;
                $scope.peihuo_add_filter.store_code = ret[0].store_code;
            });

        };
    }];

//新增配货单详情（空白）
var CunhuoPeihuoAddDetailCtrl = ['$scope', '$location', '$rootScope', 'ngDialog', 'yaoHuo',
    function ($scope, $location, $rootScope, ngDialog, yaoHuo) {
        $scope.curr = "peihuo_list";
        var window_id = 0;
        $scope.input_keywords = '';
        //类似购物车
        $scope._detail = {};
        $scope.temp_detail=[];
        var temp_arr =[];
        $scope.init_record = {};
        //上一步点击保存时：存到$rootScope.data中
        //配货单进来需要刷新单据信息(保存的信息进行刷新)
        $scope.init_record = $rootScope.local_peihuo_record;
        $scope.init_record.num = 0;
        $scope.init_record.money = 0;
        //判断要货类型
        var category_code = '';
        switch ($scope.init_record.allocate_type) {
            case "600":
                category_code = '';
                break;
//          case "601":
//              category_code = 'Z';
//              //正价商品
//              break;
//          case "602":
//              category_code = 'S';
//              //试用装
//              break;
        }
        var goods_select_click_handler = function (sku) {
            //商品选择完毕之后，需要记录并且刷新整个页面实现一个动态的改变
            if($scope._detail[sku.SkuCode] != undefined){
				$scope._detail[sku.SkuCode].num =sku.num*1;
			}else{
				$scope._detail[sku.SkuCode] = {
					'index': sku.SkuCode, //购物车的键
					'record_code': $scope.init_record.record_code,
					'sku': sku.SkuCode,
					'property_name': sku.SkuPropertyName,
					'goods_code': sku.GoodsCode,
					'goods_name': sku.GoodsName,
					'goods_name_zh_tw': sku.GoodsName_zh_tw,
					'goods_name_en': sku.GoodsName_en,
					'color_code': sku.ColorCode,
					'size_code': sku.SizeCode,
					'zhek': 1.00,
					'num': sku.num,
					'price': new Number(sku.SkuPrice).toFixed(2),
					'money': parseInt(sku.num) * parseFloat(sku.SkuPrice)
				};
				temp_arr.push({'SkuCode':sku.SkuCode});
				$scope.temp_detail = temp_arr.concat();
				$scope.temp_detail.reverse();
			}
            //刷新整个配货单
            refresh_record();
            //清空搜索框
            $scope.input_keywords = '';
            ngDialog.close(window_id);
        };

        //商品sku查询
        $scope.search_goods = function (keywords) {
            var key = new String(keywords);
            if ('' == keywords || Object.keys(key).length < 3) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_NEED
                });
                return false;
            }
            //根据要货类型搜索相关商品
            yaoHuo.sku_search_by_sku(keywords, category_code).then(function (ret) {
                if (Object.keys(ret).length == 0) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        msg: $rootScope.language.TIPS_CUNHUO_SEARCH_GOODS
                    });
                    return false;
                }
                //只有一条数据时，直接添加
                if (Object.keys(ret).length == 1) {
                    $scope.sku = ret[0];
                    $scope.sku.num
                    window_id = ngDialog.open({closeByDocument: false,
                        trapFocus: false,
                        template: './html/component/edit_num.html',
                        disableAnimation: true,
                        scope: $scope,
                        preCloseCallback: function () {
		                    $scope.close_keyboard();//关闭小键盘
		                }
                        //                        closeByDocument: false
                    });
                    //$scope.focus('input_num1');
                    $scope.open_keyboard('sku.num');
                } else {
                    $scope.goods_select_data = ret;
                    window_id = ngDialog.open({closeByDocument: false,
                        trapFocus: false,
                        template: './html/component/goods_select.html',
                        disableAnimation: true,
                        scope: $scope,
                        //                        closeByDocument: false
                    });
                }

            });
        };
        //删除一组sku
        $scope.del_sku = function (index,arrindex) {
            window_id = ngDialog.open({closeByDocument: false,
                trapFocus: false,
                template: './html/component/deleteSku.html',
                disableAnimation: true,
                scope: $scope,
                controller: ['$scope', function ($scope) {
                        //确认删除商品
                        $scope.deleteSku_submit = function () {
                            ngDialog.close(window_id);
                            delete $scope._detail[index];
                            $scope.temp_detail.splice(arrindex, 1);
                            var lenindex =  temp_arr.length - 1 -(arrindex) ;
                            temp_arr.splice(lenindex, 1);
                            refresh_record();
                        };
                        //取消删除商品
                        $scope.deleteSku_close = function () {
                            ngDialog.close(window_id);
                        };
                    }]
            });
        };

        //编辑sku的数量
        $scope.edit = function (sku) {
            $scope.sku = sku;
            $scope.sku.e_num = sku.num;
            //增加一个临时数量存储
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/component/edit.html',
                disableAnimation: true,
                scope: $scope,
                trapFocus: false,
                preCloseCallback: function () {
		                    $scope.close_keyboard();//关闭小键盘
		                }
                //                closeByDocument: false
            });
            //$scope.focus('input_num2');
            $scope.open_keyboard('sku.e_num');
        };
        //上传操作
        $scope.record_upload = function () {
            if (Object.keys($scope._detail).length == 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.MSG_WITHOUT_SELECT_GOODS
                });
                return;
            }
            var param = {};
            param.record = $scope.init_record;
            param.record_detail = $scope._detail;
            yaoHuo.upload_peihuo_remote(param).then(function (ret) {
                if (ret.data.status == 1) {
                    baison_app.api.toast({
                        title: $rootScope.language.TIP_CASHIER_TITLE,
                        msg: $rootScope.language.TIPS_CUNHUO_CONFIRM_SUCCESS
                    });
                    //如果成功就跳转到
                    $location.path('/cunhuo/peihuo_list');
                } else {
                    baison_app.api.toast({
                        msg: $rootScope.language[ret.data.code]
                    });
                }

            });
        };
        //写一个刷新整个配货单
        var refresh_record = function () {
            var num = 0;
            var money = 0;
            $.each($scope._detail, function (index, n) {
                num = parseInt(num) + parseInt(n.num);
                money = parseFloat(money) + parseInt(n.num) * parseFloat(n.price);
                n.money = n.num * n.price;
            });
            $scope.init_record.num = num;
            $scope.init_record.money = money;
        };
        //弹框处理=======================================

        //选择商品
        $scope.goods_select_click = function (sku) {
            $scope.sku = sku;
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/component/edit_num.html',
                disableAnimation: true,
                scope: $scope,
                trapFocus: false,
                preCloseCallback: function () {
                    $scope.close_keyboard();//关闭小键盘
                }
                //                closeByDocument: false
            });
            //$scope.focus('input_num1');
           $scope.open_keyboard('sku.num');
            //goods_select_click_handler(sku);
        };
        //选择商品填写数量
        $scope.save_num = function (sku) {
            var re = /^[1-9]+[0-9]*]*$/;
            if (sku.num == undefined) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EMPTY
                });
                return;
            } else if (sku.num <= 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY
                });
                return;
            } else if (!re.test(sku.num)) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                });
                return;
            }
            
            $scope.close_keyboard();//关闭小键盘
            goods_select_click_handler(sku);
            ngDialog.close(window_id);
        };
        //编辑修改数量
        $scope.save_edit = function (sku) {
            var re = /^[1-9]+[0-9]*]*$/;
            if (sku.e_num <= 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY
                });
                return;
            } else if (!re.test(sku.e_num)) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                });
                return;
            }
            $scope.close_keyboard();//关闭小键盘
            sku.num = sku.e_num;
            refresh_record();
            ngDialog.close(window_id);
        };
        //取消
        $scope.clear = function () {
            refresh_record();
            ngDialog.close(window_id);
        };
    }];

//新增配货单据详情（建议要货）
var CunhuoPeihuoAddAdviseDetailCtrl = ['$scope', '$location', '$rootScope', 'ngDialog', 'yaoHuo', 'BaseGoods',
    function ($scope, $location, $rootScope, ngDialog, yaoHuo, BaseGoods) {
        $scope.curr = "peihuo_list";
        var window_id = 0;
        $scope._detail = {};
        $scope.temp_detail=[];
        var temp_arr =[];
        $scope.init_record = {};
        $scope.input_keywords = '';
        //刷新内容显示=================================
        //配货单进来需要刷新单据信息(保存的信息进行刷新)
        $scope.init_record = $rootScope.local_peihuo_record;
        $scope.init_record.num = 0;
        $scope.init_record.money = 0;

        //判断建议要货类型
        var category_code = '';
        switch ($scope.init_record.allocate_type) {
            case "600":
                category_code = '';
                break;
//          case "601":
//              category_code = 'Z';
//              //正价商品
//              break;
//          case "602":
//              category_code = 'S';
//              //试用装
//              break;
        }

        //近30天日均销量、库存安全天数、系数、陈列数、库存数
        var sales;
        var supply_day;
        var coefficient;
        var chenlie;
        var skunum;
        //中间建议数变量
        var ly_advise;

        //获取库存安全天数和系数
        var get_supply_day_coefficient = function () {
            yaoHuo.get_item().then(function (ret) {
                supply_day = ret.data.data[0].supply_day;
                coefficient = ret.data.data[0].coefficient;
            });
        };
        get_supply_day_coefficient();

        var goods_select_click_handler = function (sku) {
			if($scope._detail[sku.SkuCode] != undefined){
				$scope._detail[sku.SkuCode].num = sku.num*1;
			}else{
				$scope._detail[sku.SkuCode] = {
					'index': sku.SkuCode, //购物车的键
					'record_code': $scope.init_record.record_code,
					'sku': sku.SkuCode,
					'property_name': sku.SkuPropertyName,
					'goods_code': sku.GoodsCode,
					'goods_name': sku.GoodsName,
					'goods_name_zh_tw': sku.GoodsName_zh_tw,
					'goods_name_en': sku.GoodsName_en,
					'color_code': sku.ColorCode,
					'size_code': sku.SizeCode,
					'zhek': 1.00,
					'num': sku.num,
					'advise_num': ly_advise, //建议订单数
					'price': new Number(sku.SkuPrice).toFixed(2),
					'money': parseInt(sku.num) * parseFloat(sku.SkuPrice)
				};
				temp_arr.push({'SkuCode':sku.SkuCode});
				$scope.temp_detail = temp_arr.concat();
				$scope.temp_detail.reverse();
			}
            refresh_record();
            $scope.input_keywords = '';
            ngDialog.close(window_id);
        };
        //列举出所有的sku(建议订单数大于1)
        var listAllSkus = function () {
            yaoHuo.get_item().then(function (ret) {
                supply_day = ret.data.data[0].supply_day;
                coefficient = ret.data.data[0].coefficient;
                yaoHuo.getAdviseNum_by_allocate_type(category_code).then(function (ret) {
                    $.each(ret, function (i, n) {
                        var sku = n;
                        sku.num//数量
                        //从本地获取账面数和陈列数
                        BaseGoods.getSkuNum_by_sku(sku.SkuCode).then(function (response) {
                            var chenlie = response.SkuChenlie;
                            var skunum = response.SkuNum;
                            yaoHuo.get_sales_by_day(sku, 30).then(function (ret) {
                                if (ret[0].total_num == '') {
                                    sales = 0;
                                } else {
                                    sales = ret[0].total_num;
                                }
                                var advise_num = new Number(sales) * supply_day * coefficient + (new Number(chenlie)) - (new Number(skunum));
                                sku.num = advise_num;
                                ly_advise = advise_num;
                                if (ly_advise >= 1) {
                                    goods_select_click_handler(sku);
                                }
                            });
                        });
                    });
                });
            });
        };

        listAllSkus();

        //商品sku查询
        $scope.search_goods = function (keywords) {
            var key = new String(keywords);
            if ('' == keywords || Object.keys(key).length < 3) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_NEED
                });
                return false;
            }
            yaoHuo.sku_search_by_sku(keywords, category_code).then(function (ret) {
                if (Object.keys(ret).length == 0) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.TIP_CASHIER_TITLE,
                        msg: $rootScope.language.TIPS_CUNHUO_SEARCH_GOODS
                    });
                    return false;
                }
                //只有一条数据时，直接添加
                if (Object.keys(ret).length == 1) {
                    $scope.sku = ret[0];
                    $scope.sku.num
                    window_id = ngDialog.open({closeByDocument: false,
                       
                        template: './html/component/edit_num.html',
                        disableAnimation: true,
                        scope: $scope,
                        trapFocus: false,
                        preCloseCallback: function () {
		                    $scope.close_keyboard();//关闭小键盘
		                },
                        //                        closeByDocument: false,
                        controller: ['$scope',
                            function ($scope) {
                                //从本地表里面读取库存和陈列数
                                BaseGoods.getSkuNum_by_sku($scope.sku.SkuCode).then(function (ret) {
                                    chenlie = ret.SkuChenlie;
                                    skunum = ret.SkuNum;
                                    yaoHuo.get_sales_by_day($scope.sku, 30).then(function (ret) {
                                        if (ret[0].total_num == '') {
                                            sales = 0;
                                        } else {
                                            sales = ret[0].total_num;
                                        }
                                        var advise_num = new Number(sales) * supply_day * coefficient + (new Number(chenlie)) - (new Number(skunum));
                                        $scope.sku.num = advise_num;
                                        //默认等于建议要货数量
                                        ly_advise = advise_num;
                                    });
                                });

                            }]

                    });
                    //$scope.focus('input_num1');
                    $scope.open_keyboard('sku.num');
                } else {
                    $scope.goods_select_data = ret;
                    window_id = ngDialog.open({closeByDocument: false,
                        template: './html/component/goods_select.html',
                        disableAnimation: true,
                        trapFocus: false,
                        scope: $scope,
                        //                        closeByDocument: false
                    });
                }
            });
        };

        //删除一组sku
        $scope.del_sku = function (index,arrindex) {
            window_id = ngDialog.open({closeByDocument: false,
                trapFocus: false,
                template: './html/component/deleteSku.html',
                disableAnimation: true,
                scope: $scope,
                controller: ['$scope', function ($scope) {
                        //确认删除商品
                        $scope.deleteSku_submit = function () {
                            ngDialog.close(window_id);
                            delete $scope._detail[index];
                            $scope.temp_detail.splice(arrindex, 1);
                            var lenindex =  temp_arr.length - 1 -(arrindex) ;
                            temp_arr.splice(lenindex, 1);
                            refresh_record();
                        };
                        //取消删除商品
                        $scope.deleteSku_close = function () {
                            ngDialog.close(window_id);
                        };
                    }]
            });
        };

        //编辑sku的数量
        $scope.edit = function (sku) {
            $scope.sku = sku;
            $scope.sku.e_num = sku.num;
            //增加一个临时数量存储
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/component/edit.html',
                disableAnimation: true,
                trapFocus: false,
                scope: $scope,
                preCloseCallback: function () {
		                    $scope.close_keyboard();//关闭小键盘
		                }
                //                closeByDocument: false
            });
            //$scope.focus('input_num2');
            $scope.open_keyboard('sku.e_num');
        };
        //上传操作
        $scope.record_upload = function () {
            if (Object.keys($scope._detail).length == 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.MSG_WITHOUT_SELECT_GOODS
                });
                return;
            }
            var param = {};
            param.record = $scope.init_record;
            param.record_detail = $scope._detail;
            yaoHuo.upload_peihuo_remote(param).then(function (ret) {
                if (ret.data.status == 1) {
                    baison_app.api.toast({
                        msg: $rootScope.language.TIPS_CUNHUO_CONFIRM_SUCCESS
                    });
                    //如果成功就跳转到
                    $location.path('/cunhuo/peihuo_list');
                } else {
                    baison_app.api.toast({
                        msg: $rootScope.language[ret.data.code]
                    });
                }

            });
        };
        //写一个刷新整个配货单
        var refresh_record = function () {
            var num = 0;
            var money = 0;
            $.each($scope._detail, function (index, n) {
                num = parseInt(num) + parseInt(n.num);
                money = parseFloat(money) + parseInt(n.num) * parseFloat(n.price);
                n.money = n.num * n.price;
            });
            $scope.init_record.num = num;
            $scope.init_record.money = money;
        };

        //弹框处理=======================================
        //选择商品
        $scope.goods_select_click = function (sku) {
            $scope.sku = sku;
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/component/edit_num.html',
                disableAnimation: true,
                trapFocus: false,
                scope: $scope,
                preCloseCallback: function () {
                    $scope.close_keyboard();//关闭小键盘
                },
                //                closeByDocument: false,
                controller: ['$scope',
                    function ($scope) {
                        //从本地读取库存和陈列数
                        BaseGoods.getSkuNum_by_sku(sku.SkuCode).then(function (ret) {
                            chenlie = ret.SkuChenlie;
                            skunum = ret.SkuNum;
                            yaoHuo.get_sales_by_day(sku, 30).then(function (ret) {
                                if (ret[0].total_num == '') {
                                    sales = 0;
                                } else {
                                    sales = ret[0].total_num;
                                }
                                var advise_num = new Number(sales) * supply_day * coefficient + (new Number(chenlie)) - (new Number(skunum));
                                $scope.sku.num = advise_num;
                                //默认等于建议要货数量
                                ly_advise = advise_num;
                            });
                        });

                    }]

            });
            //$scope.focus('input_num1');
            $scope.open_keyboard('sku.num');
        };
        //选择商品填写数量
        $scope.save_num = function (sku) {
            var re = /^[1-9]+[0-9]*]*$/;
            if (sku.num == undefined) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EMPTY
                });
                return;
            } else if (sku.num <= 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY
                });
                return;
            } else if (!re.test(sku.num)) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                });
                return;
            }
            $scope.close_keyboard();//关闭小键盘
            goods_select_click_handler(sku);
            ngDialog.close(window_id);
        };
        //保存编辑
        $scope.save_edit = function (sku) {
            var re = /^[1-9]+[0-9]*]*$/;
            if (sku.e_num <= 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY
                });
                return;
            } else if (!re.test(sku.e_num)) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                });
                return;
            }
            $scope.close_keyboard();//关闭小键盘
            sku.num = sku.e_num;
            refresh_record();
            ngDialog.close(window_id);
        };
        //取消
        $scope.clear = function (sku) {
            refresh_record();
            ngDialog.close(window_id);
        };
    }];

//入库单列表
var CunhuoRukuListCtrl = ['$scope', '$rootScope', 'ngDialog', 'ruKu','ThirdDev',
    function ($scope, $rootScope, ngDialog, ruKu,ThirdDev) {
        $scope.curr = "ruku_list";
        $scope.is_lqx = ThirdDev.is_lqx();
        $scope.filter = {};
        //查询条件
        $scope.filter.record_code = '';
        $scope.filter.record_time_start = '';
        $scope.filter.record_time_end = '';
        $scope.filter.fOrder = '';
        var window_id = 0;

        $scope.active_switch_0 = false;
        $scope.active_switch_1 = false;
        $scope.active_switch_2 = true;
        //待处理查询
        $scope.suspenseOrder = function () {
            $scope.active_switch_1 = false;
            $scope.active_switch_2 = false;
            $scope.active_switch_0 = true;
            $scope.filter.fOrder = 0;
            //表示未入库的单据
            search_api({
                shop_code: $rootScope.current_shop.ShopCode,
                is_shop_stock_in: $scope.filter.fOrder
            });
        };
        //已处理
        $scope.alreadyOrder = function () {
            $scope.active_switch_0 = false;
            $scope.active_switch_2 = false;
            $scope.active_switch_1 = true;
            $scope.filter.fOrder = 1;
            //表示已入库的单据
            search_api({
                shop_code: $rootScope.current_shop.ShopCode,
                is_shop_stock_in: $scope.filter.fOrder
            });
        };
        //全部
        $scope.allOrder = function () {
            $scope.active_switch_0 = false;
            $scope.active_switch_1 = false;
            $scope.active_switch_2 = true;
            //          $scope.filter.fOrder = 2;   //表示全部
            search_api({
                shop_code: $rootScope.current_shop.ShopCode
            });
        };
        //查询
        $scope.search_ruku = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
            $scope.filter.is_shop_stock_in = $scope.filter.fOrder;
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/cunhuo/ruku/ruku_select.html',
                disableAnimation: true,
                trapFocus: false,
                scope: $scope
                        //                disableAnimation : true,
                        //                        closeByDocument: false
            });
        };
        //查询框重置
        $scope.clear = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
        };
        //点击加载更多
        $scope.scoll = {};
        //滚动加载器
        $scope.scoll.busy = false;
        $scope.scoll.nextpage = function () {
            if ($scope.scoll.busy)
                return;
            baison_app.api.toast({
                msg: $rootScope.language.COMMON_LOADING
            });
            $scope.scoll.busy = true;
            var param = {};
            param.is_pre = 1;
            param.shop_code = $rootScope.current_shop.ShopCode;
            param.is_shop_stock_in = $scope.filter.fOrder;
            //判断是 以处理；未处理；还是全部
            if ($scope.ruku_list.length > 0) {
                param.day = $scope.ruku_list[$scope.ruku_list.length - 1]['key'];
            }
            ruKu.ruku_search_api(param).then(function (ret) {
                if (ret.data.status == 1) {
                    for (i in ret.data.data) {
                        $scope.ruku_list.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.scoll.busy = false;
                } else if (ret.data.status == -1) {
                    baison_app.api.toast({
                        msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
                    });
                    $scope.scoll.busy = false;
                    $scope.is_show = "";
                }
            });
        };
        //私有方法===============================================================
        //从服务器搜索
        var search_api = function (param) {
            ruKu.ruku_search_api(param).then(function (ret) {
                if (ret.data.status != 1) {
                    //更多按钮不显示
                    $scope.is_show = "";
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.TIP_CASHIER_TITLE,
                        msg: $rootScope.language[ret.data.code]
                    });
                    $scope.ruku_list = [];
                    return;
                } else if (ret.data.status == 1) {
                    $scope.is_show = "true";
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                        //第一个日期的
                    }
                    $scope.ruku_list = data;
                }
            }).catch(function (err) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
        };
        //弹框处理================================================================
        //入库单查询（按时间查询）
        $scope.ruku_select = function (param) {
            if (param.record_time_start == '' || param.record_time_end == '') {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME,
                });
                return;
            }
            if (param.record_time_start > param.record_time_end) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME_LIMIT,
                });
                return;
            }
            ruKu.ruku_select(param).then(function (ret) {
                if (ret.data.status != 1) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.TIP_CASHIER_TITLE,
                        msg: $rootScope.language[ret.data.code]
                    });
                    return;
                } else if (ret.data.status == 1) {
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                        //第一个日期的
                    }
                    $scope.ruku_list = data;
                }
            }).catch(function (err) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
            ngDialog.close(window_id);
        };
        //默认从服务器拿数据
        search_api({
            shop_code: $rootScope.current_shop.ShopCode
        });
    }];
//入库单列表细节信息
var CunhuoRukuDetailCtrl = ['$scope', '$rootScope', 'Print', '$location', '$routeParams', 'ngDialog', 'ruKu', 'BaseGoods','ThirdDev',
    function ($scope, $rootScope, Print, $location, $routeParams, ngDialog, ruKu, BaseGoods,ThirdDev) {
        $scope.curr = "ruku_list";
        $scope.is_lqx = ThirdDev.is_lqx();
        var filter = {};
        filter.record_code = $routeParams.record_code;
        //入库单单据明细
        ruKu.ruku_list_detail_search_by_code(filter).then(function (ret) {
            //林清轩入库：暂时用横调入库这个权限判断
            if (ThirdDev.is_lqx()) {   //$rootScope.purview['\/DiaoboRuku'].show == 0
                //是否需要入库操作
                if (ret.data.data.record.is_sure == 1 && ret.data.data.record.is_allocate_stock_out == 1 && ret.data.data.record.is_shop_stock_in == 0) {
                    $scope.is_ruku = "true";
                }
                $scope.ruku_list_detail = ret.data.data;
                $.each($scope.ruku_list_detail.record_detail, function (i, n) {
                    $scope.ruku_list_detail.record_detail[i]['GoodsName'] = '';
                    BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
                        $scope.ruku_list_detail.record_detail[i]['GoodsName'] = ret.GoodsName;
                    });
                });
            } else if(!ThirdDev.is_lqx()){
                //ipos
                if (ret.data.data.record.is_sure == 0) {
                    $scope.is_ruku = "true";
                }
                $scope.ruku_list_detail = ret.data.data;
                $.each($scope.ruku_list_detail.record_detail, function (i, n) {
                    $scope.ruku_list_detail.record_detail[i]['GoodsName'] = '';
                    if (n.goods_name != '' && n.goods_name !== undefined) {
                        $scope.ruku_list_detail.record_detail[i]['GoodsName'] = n.goods_name;
                    } else {
                        BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
                            $scope.ruku_list_detail.record_detail[i]['GoodsName'] = ret.GoodsName;
                        });
                    }
                });
            }

        });
        //入库操作
        $scope.flag = false;
        $scope.stock_in = function () {
            if ($scope.flag) {
                return;
            }
            $scope.flag = true;
            var param = {};
            //林清轩
            if (ThirdDev.is_lqx()) {  //$rootScope.purview['\/DiaoboRuku'].show == 0
                param.record_code = $scope.ruku_list_detail.record.record_code;
                param.detail = $scope.ruku_list_detail.record_detail;
                //传一个操作员
                param.user_code = $rootScope.user.UserCode;
            } else {
                param.record_code = filter.record_code;
                //ipos传一个操作员
                param.user_code = $rootScope.user.UserCode;
            }
            //入库操作
            ruKu.allocate_record_stock_in_detail(param).then(function (ret) {
                if (ret.data.status == 1) {
                    //库存相应的变化
                    $.each($scope.ruku_list_detail.record_detail, function (i, n) {
                        //库存数量增加
                        ruKu.update_local_SkuNum(n.sku, n.num);
                    });
                    $scope.is_ruku = "";
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        msg: $rootScope.language[ret.data.code]
                    });
                }
            }).catch(function (msg) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
        };

        //added by lqx maowei on 20170119打印配货入库详细
        $scope.to_print_rukudetail = function () {
            ruKu.ruku_list_detail_search_by_code(filter).then(function (ret) {
                var rukudetail = ret.data.data;
                    Print.rukudetail_print('', rukudetail);
            });
        };

        //关闭按钮
        $scope.come_back = function () {
            $location.path('/cunhuo/ruku');
        };
    }];

//退库单
var CunhuoTuikuListCtrl = ['$scope', '$rootScope', 'ngDialog', 'tuiKu','ThirdDev',
    function ($scope, $rootScope, ngDialog, tuiKu,ThirdDev) {
        $scope.curr = "tuiku_list";
        $scope.is_lqx = ThirdDev.is_lqx();
        //查询条件
        $scope.filter = {};
        $scope.filter.record_code = '';
        $scope.filter.record_time_start = '';
        $scope.filter.record_time_end = '';
        var window_id = 0;
        //点击加载更多
        $scope.scoll = {};
        //滚动加载器
        $scope.scoll.busy = false;
        $scope.scoll.nextpage = function () {
            if ($scope.scoll.busy)
                return;
            baison_app.api.toast({
                msg: $rootScope.language.COMMON_LOADING
            });
            $scope.scoll.busy = true;
            var param = {};
            param.is_pre = 1;
            param.shop_code = $rootScope.current_shop.ShopCode;
            if ($scope.tuiku_list.length > 0) {
                param.day = $scope.tuiku_list[$scope.tuiku_list.length - 1]['key'];
            }
            tuiKu.tuiku_search_api(param).then(function (ret) {
                if (ret.data.status == 1) {
                    for (i in ret.data.data) {
                        $scope.tuiku_list.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.scoll.busy = false;
                } else if (ret.data.status == -1) {
                    baison_app.api.toast({
                        msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
                    });
                    $scope.scoll.busy = false;
                    $scope.is_show = "";
                }
            });
        };
        //查询
        $scope.search = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
            window_id = ngDialog.open({closeByDocument: false,
                trapFocus: false,
                template: './html/cunhuo/tuiku/tuiku_select.html',
                disableAnimation: true,
                scope: $scope,
                //                disableAnimation : true,
                //                        closeByDocument: false
            });
        };
        //重置按钮
        $scope.clear = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
        };
        //默认查找服务器
        tuiKu.tuiku_search_api({
            shop_code: $rootScope.current_shop.ShopCode
        }).then(function (ret) {
            if (ret.data.status != 1) {
                $scope.is_show = "";
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    msg: $rootScope.language[ret.data.code]
                });
                return;
            } else if (ret.data.status == 1) {
                $scope.is_show = "true";
                var data = [];
                for (i in ret.data.data) {
                    data.push({
                        key: i,
                        value: ret.data.data[i]
                    });
                    //第一个日期的
                }
                $scope.tuiku_list = data;
            }
        }).catch(function (err) {
            baison_app.api.toast({
                msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
            });
        });
        //弹框处理================================================================
        $scope.tuiku_select = function (filterData) {
            if (filterData.record_time_start == '' || filterData.record_time_end == '') {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME
                });
                return;
            }
            if (filterData.record_time_start > filterData.record_time_end) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME_LIMIT
                });
                return;
            }
            tuiKu.tuiku_select(filterData).then(function (ret) {
                if (ret.data.status != 1) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language[ret.data.code]
                    });
                    return;
                } else if (ret.data.status == 1) {
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                        //第一个日期的
                    }
                    $scope.tuiku_list = data;
                }
            }).catch(function (err) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
            ngDialog.close(window_id);
        };

    }];

//退库细节
var CunhuoTuikuDetailCtrl = ['$scope', '$rootScope', 'Print', '$location', '$routeParams', 'tuiKu', 'BaseGoods','ThirdDev',
    function ($scope, $rootScope, Print, $location, $routeParams, tuiKu, BaseGoods,ThirdDev) {
        $scope.curr = "tuiku_list";
        $scope.is_lqx = ThirdDev.is_lqx();
        var filter = {};
        filter.record_code = $routeParams.record_code;
        //退库单单据明细
        tuiKu.tuiku_list_detail_search_by_code(filter).then(function (ret) {
            //判断是否需要退库(权限控制lqx使用)
            if (ret.data.data.record.is_sure == 1 && ret.data.data.record.is_shop_stock_out == 0) {
                //林清轩
                if (ThirdDev.is_lqx()) {  //$rootScope.purview['\/cunhuo\/tuiku'].show == 1
                    $scope.is_tuiku = "true";
                }
            }

            $scope.tuiku_list_detail = ret.data.data;
            $.each($scope.tuiku_list_detail.record_detail, function (i, n) {
                $scope.tuiku_list_detail.record_detail[i]['GoodsName'] = '';
                if (n.goods_name != '' && n.goods_name !== undefined) {
                    $scope.tuiku_list_detail.record_detail[i]['GoodsName'] = n.goods_name;
                } else {
                    BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
                        $scope.tuiku_list_detail.record_detail[i]['GoodsName'] = ret.GoodsName;
                    });
                }
            });
        });
        //权限控制lqx使用
        if (ThirdDev.is_lqx()) {  //$rootScope.purview['\/cunhuo\/tuiku'].show == 1
            //退库操作
            $scope.stock_out = function () {
                var param = {};
                param.record_code = $scope.tuiku_list_detail.record.record_code;
                //传一个操作员
                param.user_code = $rootScope.user.UserCode;
                tuiKu.return_record_stock_in_detail(param).then(function (ret) {
                    if (ret.data.status == 1) {
                        //库存相应的变化
                        $.each($scope.tuiku_list_detail.record_detail, function (i, n) {
                            tuiKu.update_local_SkuNum(n.sku, n.num);
                        });
                        $scope.is_tuiku = "";
                        baison_app.api.toast({
                            buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                            title: $rootScope.language.COMMON_TITLE_HINT,
                            msg: $rootScope.language[ret.data.code]
                        });
                    }
                });
            };
        }

        //返回按钮
        $scope.come_back = function () {
            $location.path('/cunhuo/tuiku_list');
        };

        //added by lqx maowei on 20170112 退库打印
        $scope.to_print_tuikudetail = function(){
            tuiKu.tuiku_list_detail_search_by_code(filter).then(function (ret) {
                $scope.tuiku_list_detail = ret.data.data;
                var tuikudetail = ret.data.data;
                Print.tuikudetail_print('', tuikudetail);
            });
        }
    }];

//退库新增(空白申请单)
var CunhuoTuikuAddCtrl = ['$scope', '$rootScope', '$location', 'ngDialog', 'timeStamp2String', 'PosUser', 'tuiKu', 'yaoHuo','ThirdDev',
    function ($scope, $rootScope, $location, ngDialog, timeStamp2String, PosUser, tuiKu, yaoHuo,ThirdDev) {
        $scope.curr = "tuiku_list";
        $scope.is_lqx = ThirdDev.is_lqx();
        $scope.filter = {};
        //退货类型选择
        $scope.filter.allocate_type_option = [];
        //营业员选择
        $scope.filter.user_code_option = [];
        //仓库选择
        $scope.filter.store_code_option = [];
        //林清轩
        if (ThirdDev.is_lqx()) { //$rootScope.purview['\/cunhuo\/chuku'].show == 0
            $scope.filter.ck = "总仓";
        }

        //营业员下拉
        var user_filter = {
            'ShopCode': $rootScope.current_shop.ShopCode,
            'UserStatus': 1
        };
        //单据退货类型下拉
        var record_type = {
            'record_type_property': 7
        };

        //仓库下拉
        var ck_filter = {
            'status': 1
        };
        $scope.filter.record_code = yaoHuo.create_fast_bill_sn('return');
        //生成单据编号
        $scope.filter.record_time = timeStamp2String(0, 'datetime');
        //日期
        PosUser.get_list_by_cond(user_filter).then(function (ret) {//营业员下拉
            $scope.filter.user_code_option = ret;
        });
        //退货类型下拉
        yaoHuo.record_type_list(record_type).then(function (ret) {
            $scope.filter.allocate_type_option = ret;
        });
        //ipos
        if (!ThirdDev.is_lqx()) { //$rootScope.purview['\/cunhuo\/chuku'].show == 1
            //仓库下拉
            yaoHuo.select_storage_list(ck_filter).then(function (ret) {
                 if(ret.length>0){
                 	$scope.filter.store_code = ret[0].store_code;
                	$scope.filter.store_name = ret[0].store_name;
                 }
                $scope.filter.store_code_option = ret;
            });
        }


        //退货原因
//      $scope.filter.tuihuo_reason = [{
//              "code": "001",
//              "name": $rootScope.language.TIPS_CUNHUO_RETURN_REASON1
//          }, {
//              "code": "002",
//              "name": $rootScope.language.TIPS_CUNHUO_RETURN_REASON2
//          }, {
//              "code": "003",
//              "name": $rootScope.language.TIPS_CUNHUO_RETURN_REASON3
//          }, {
//              "code": "004",
//              "name": $rootScope.language.TIPS_CUNHUO_RETURN_REASON4
//          }, {
//              "code": "005",
//              "name": $rootScope.language.TIPS_CUNHUO_RETURN_REASON5
//          }, {
//              "code": "006",
//              "name": $rootScope.language.TIPS_CUNHUO_RETURN_REASON6
//          }, {
//              "code": "007",
//              "name": $rootScope.language.TIPS_CUNHUO_RETURN_REASON7
//          }];
        //保存到本地
        $scope.save_local = function (filter) {
            //林清轩
            if (ThirdDev.is_lqx()) {//$rootScope.purview['\/cunhuo\/chuku'].show == 0
                if (filter.return_type === undefined || filter.return_type == null || filter.user_code === undefined || filter.user_code == null) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_INFO_NEED
                    });
                    return false;
                }
            } else {
                if (filter.return_type === undefined || filter.return_type == null || filter.user_code === undefined || filter.user_code == null || filter.store_code === undefined || filter.store_code == null) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_INFO_NEED
                    });
                    return false;
                }
            }
            //ipos
            if (!ThirdDev.is_lqx()) {  //$rootScope.purview['\/cunhuo\/chuku'].show == 1
                var localData = tuiKu.save_local(filter);
                yaoHuo.getStoreName_by_code(localData.store_code).then(function (response) {
                    localData.store_name = response[0].store_name;
                    $rootScope.local_tuiku_record = localData;
                    $location.path('/cunhuo/tuiku_add_detail');
                });
            } else {
                $rootScope.local_tuiku_record = tuiKu.save_local(filter);
                $location.path('/cunhuo/tuiku_add_detail');
            }
        };
        //重置按钮
        $scope.reset = function (filter) {
            filter.return_type = filter.user_code  = undefined;
        };
    }];

//退库新增（全退）
var CunhuoTuikuAddAllCtrl = ['$scope', '$rootScope', '$location', 'ngDialog', 'timeStamp2String', 'PosUser', 'tuiKu', 'yaoHuo',
    function ($scope, $rootScope, $location, ngDialog, timeStamp2String, PosUser, tuiKu, yaoHuo) {
        $scope.curr = "tuiku_list";
        $scope.filter = {};
        //退货类型选择
        $scope.filter.allocate_type_option = [];
        //营业员选择
        $scope.filter.user_code_option = [];
        $scope.filter.ck = $rootScope.language.TIPS_CUNHUO_FILTER_SHOP;
        //营业员下拉
        var user_filter = {
            'ShopCode': $rootScope.current_shop.ShopCode,
            'UserStatus': 1
        };
        //单据退货类型下拉
        var record_type = {
            'record_type_property': 7
        };
        $scope.filter.record_code = yaoHuo.create_fast_bill_sn('return');
        //生成单据编号
        $scope.filter.record_time = timeStamp2String(0, 'datetime');
        //日期
        PosUser.get_list_by_cond(user_filter).then(function (ret) {//营业员下拉
            $scope.filter.user_code_option = ret;
        });
        //退货类型下拉
        yaoHuo.record_type_list(record_type).then(function (ret) {
            $scope.filter.allocate_type_option = ret;
        });
        //仓库目前都是总仓
        //退货原因
//      $scope.filter.tuihuo_reason = [{
//              "code": "006",
//              "name": $rootScope.language.TIPS_CUNHUO_RETURN_REASON6
//          }, {
//              "code": "008",
//              "name": $rootScope.language.TIPS_CUNHUO_RETURN_REASON7
//          }];
        //保存到本地
        $scope.save_local = function (filter) {
            if (filter.return_type === undefined || filter.return_type == null || filter.user_code === undefined || filter.user_code == null) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_INFO_NEED
                });
                return false;
            }
            $rootScope.local_tuiku_record = tuiKu.save_local(filter);
            $location.path('/cunhuo/tuiku_addAll_detail');
        };
        //重置按钮
        $scope.reset = function (filter) {
            filter.return_type = filter.user_code = undefined;
        };

    }];

//退库新增详情(全退申请)
var CunhuoTuikuAddAllDetailCtrl = ['$scope', '$rootScope', '$location', 'ngDialog', 'tuiKu', 'BaseGoods',
    function ($scope, $rootScope, $location, ngDialog, tuiKu, BaseGoods) {
        $scope.curr = "tuiku_list";
        $scope.record = $rootScope.local_tuiku_record;
        $scope.record.num = 0;
        //初始单据信息：数量和总价为0
        $scope.record.money = 0;
        var window_id = 0;
        $scope._detail = {};
        $scope.temp_detail=[];
        var temp_arr =[];
        $scope.input_keywords = '';
        var length = 100;
        //点击搜索按钮
        var listAllSkus = function () {
            BaseGoods.getAllReturnsSkus(0, length).then(function (ret) {
                $scope.is_show = "true";
                $scope.is_upload = "";
                $.each(ret, function (i, n) {
                    var sku = n;
                    sku.num = n.SkuNum;
                    if (sku.num > 0) {
                        goods_select_click_handler(sku);
                    }
                });
            });
        };
        listAllSkus();

        //下一页
        $scope.next_page = function () {
            BaseGoods.getAllReturnsSkus(length, 100).then(function (ret) {
                length = length + ret.length;
                if (ret.length > 0) {
                    $.each(ret, function (i, n) {
                        var sku = n;
                        sku.num = n.SkuNum;
                        if (sku.num > 0) {
                            goods_select_click_handler(sku);
                        }
                    });
                } else {
                    baison_app.api.toast({
                        msg: $rootScope.language.TIPS_CUNHUO_MESSAGE,
                    });
                    $scope.is_show = "";
                    $scope.is_upload = "true";
                }
            });
        };
        //商品sku查询
        $scope.search_goods = function (keywords) {
            var key = new String(keywords);
            if ('' == keywords || Object.keys(key).length < 3) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_NEED
                });
                return false;
            }
            tuiKu.sku_search_by_sku(keywords).then(function (ret) {
                if (Object.keys(ret).length == 0) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_SEARCH_GOODS
                    });
                    return false;
                }
                //只有一条数据时，直接添加
                if (Object.keys(ret).length == 1) {
                    $scope.sku = ret[0];
                    $scope.sku.num = $scope.sku.SkuNum;
                    //默认数量等于库存数
                    window_id = ngDialog.open({closeByDocument: false,

                        template: './html/component/edit_num.html',
                        disableAnimation: true,
                        scope: $scope,
                        trapFocus: false,
                        preCloseCallback: function () {
		                    $scope.close_keyboard();//关闭小键盘
		                }
                                //                        closeByDocument: false
                    });
                    //$scope.focus('input_num1');
            		$scope.open_keyboard('sku.num');
                } else {
                    $scope.goods_select_data = ret;
                    window_id = ngDialog.open({closeByDocument: false,
                        template: './html/component/goods_select.html',
                        disableAnimation: true,
                        scope: $scope,
                        trapFocus: false
                                //                        closeByDocument: false
                    });
                }

            });
            
        };
        //上传退库单据上传
        $scope.record_upload = function () {
            if (Object.keys($scope._detail).length == 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    msg: $rootScope.language.MSG_WITHOUT_SELECT_GOODS
                });
                return;
            }
            var param = {};
            param.record = $scope.record;
            param.record_detail = $scope._detail;
            tuiKu.return_record_add_api(param).then(function (ret) {
                if (ret.data.status == 1) {
                    baison_app.api.toast({
                        msg: $rootScope.language.TIPS_CUNHUO_CONFIRM_SUCCESS
                    });
                    //如果成功就跳转到
                    $location.path('/cunhuo/tuiku_list');
                } else {
                    baison_app.api.toast({
                        msg: $rootScope.language[ret.data.code]
                    });
                }
            });
        };
        //删除一组sku
        $scope.del_sku = function (index,arrindex) {
            window_id = ngDialog.open({closeByDocument: false,
                trapFocus: false,
                template: './html/component/deleteSku.html',
                disableAnimation: true,
                scope: $scope,
                controller: ['$scope', function ($scope) {
                        //确认删除商品
                        $scope.deleteSku_submit = function () {
                            ngDialog.close(window_id);
                            delete $scope._detail[index];
                            $scope.temp_detail.splice(arrindex, 1);
                            var lenindex =  temp_arr.length - 1 -(arrindex) ;
                            temp_arr.splice(lenindex, 1);
                            refresh_record();
                        };
                        //取消删除商品
                        $scope.deleteSku_close = function () {
                            ngDialog.close(window_id);
                        };
                    }]
            });
        };

        //编辑sku的数量
        $scope.edit = function (sku) {
            $scope.sku = sku;
            $scope.sku.e_num = sku.num;
            //增加一个临时数量存储
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/component/edit.html',
                disableAnimation: true,
                trapFocus: false,
                scope: $scope,
                preCloseCallback: function () {
		                    $scope.close_keyboard();//关闭小键盘
		                }
                        //                closeByDocument: false
            });
            //$scope.focus('input_num2');
            $scope.open_keyboard('sku.e_num');
        };
        //写一个刷新整个配货单
        var refresh_record = function () {
            var num = 0;
            var money = 0;
            $.each($scope._detail, function (index, n) {
                num = parseInt(num) + parseInt(n.num);
                money = parseFloat(money) + parseInt(n.num) * parseFloat(n.price);
                n.money = n.num * n.price;
            });
            $scope.record.num = num;
            $scope.record.money = money;
        };
        var goods_select_click_handler = function (sku) {
            //商品选择完毕之后，需要记录并且刷新整个页面实现一个动态的改变
			if($scope._detail[sku.SkuCode] != undefined){
				$scope._detail[sku.SkuCode].num = sku.num*1;
			}else{
				$scope._detail[sku.SkuCode] = {
					'index': sku.SkuCode,
					'record_code': $scope.record.record_code,
					'sku': sku.SkuCode,
					'property_name': sku.SkuPropertyName,
					'goods_code': sku.GoodsCode,
					'goods_name': sku.GoodsName,
					'goods_name_zh_tw': sku.GoodsName_zh_tw,
					'goods_name_en': sku.GoodsName_en,
					'color_code': sku.ColorCode,
					'size_code': sku.SizeCode,
					'zhek': 1,
					'num': sku.num,
					'price': new Number(sku.SkuPrice).toFixed(2),
					'money': parseInt(sku.num) * parseFloat(sku.SkuPrice),
					'SkuNum': sku.SkuNum //账面数sku.SkuNum
				};
				temp_arr.push({'SkuCode':sku.SkuCode});
				$scope.temp_detail = temp_arr.concat();
				$scope.temp_detail.reverse();
			}
            //刷新整个配货单
            refresh_record();
            //清空搜索框
            $scope.input_keywords = '';
            ngDialog.close(window_id);
        };
        //弹框处理====================================
        //选择商品
        $scope.goods_select_click = function (sku) {
            $scope.sku = sku;
            $scope.sku.num = sku.SkuNum;
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/component/edit_num.html',
                disableAnimation: true,
                trapFocus: false,
                scope: $scope,
                preCloseCallback: function () {
                    $scope.close_keyboard();//关闭小键盘
                }
                        //                closeByDocument: false
            });
            //$scope.focus('input_num1');
            $scope.open_keyboard('sku.num');
            //goods_select_click_handler(sku);
        };
        //选择商品填写数量
        $scope.save_num = function (sku) {
            var re = /^[1-9]+[0-9]*]*$/;
            if (sku.num == undefined) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EMPTY
                });
                return;
            } else if (sku.num <= 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY
                });
                return;
            } else if (!re.test(sku.num)) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                });
                return;
            }
            $scope.close_keyboard();//关闭小键盘
            goods_select_click_handler(sku);
            ngDialog.close(window_id);
        };
        //保存编辑
        $scope.save_edit = function (sku) {
            var re = /^[1-9]+[0-9]*]*$/;
            if (sku.e_num <= 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY
                });
                return;
            } else if (!re.test(sku.e_num)) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                });
                return;
            }
            $scope.close_keyboard();//关闭小键盘
            sku.num = sku.e_num;
            refresh_record();
            ngDialog.close(window_id);
        };
        $scope.clear = function () {
            refresh_record();
            ngDialog.close(window_id);
        };
    }];
//退库新增详情(空白申请)
var CunhuoTuikuAddDetailCtrl = ['$scope', '$rootScope', '$location', 'ngDialog', 'tuiKu',
    function ($scope, $rootScope, $location, ngDialog, tuiKu) {
        $scope.curr = "tuiku_list";
        $scope.record = $rootScope.local_tuiku_record;
        $scope.record.num = 0;
        //初始单据信息：数量和总价为0
        $scope.record.money = 0;
        $scope.input_keywords = '';
        var window_id = 0;
        //输入商品查询字段
        $scope._detail = {};
        $scope.temp_detail=[];
        var temp_arr =[];
        //类似购物车
        //点击搜索按钮
        $scope.search_goods = function (keywords) {
            var key = new String(keywords);
            if ('' == keywords || key.length < 3) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_NEED
                });
                return false;
            }
            tuiKu.sku_search_by_sku(keywords).then(function (ret) {
                if (ret.length == 0) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_SEARCH_GOODS
                    });
                    return false;
                }
                //只有一条数据时,不需要弹框
                if (ret.length == 1) {
                    $scope.sku = ret[0];
                    $scope.sku.num
                    window_id = ngDialog.open({closeByDocument: false,
                        template: './html/component/edit_num.html',
                        disableAnimation: true,
                        scope: $scope,
                        trapFocus: false,
                        preCloseCallback: function () {
		                    $scope.close_keyboard();//关闭小键盘
		                }
                                //                        closeByDocument: false
                    });
                    //$scope.focus('input_num1');
                    $scope.open_keyboard('sku.num');
                } else {
                    $scope.goods_select_data = ret;
                    window_id = ngDialog.open({closeByDocument: false,
                        template: './html/component/goods_select.html',
                        disableAnimation: true,
                        scope: $scope,
                        trapFocus: false
                                //                        disableAnimation : true,
                                //                                closeByDocument: false
                    });
                }
            });
        };
        //上传退库单据上传
        $scope.record_upload = function () {
            if (Object.keys($scope._detail).length == 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.MSG_WITHOUT_SELECT_GOODS
                });
                return;
            }
            var param = {};
            param.record = $scope.record;
            param.record_detail = $scope._detail;
            tuiKu.return_record_add_api(param).then(function (ret) {
                if (ret.data.status == 1) {
                    baison_app.api.toast({
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_CONFIRM_SUCCESS
                    });
                    //如果成功就跳转到
                    $location.path('/cunhuo/tuiku_list');
                } else {
                    baison_app.api.toast({
                        msg: $rootScope.language[ret.data.code]
                    });
                }
            });
        };
        //删除一组sku
        $scope.del_sku = function (index,arrindex) {
            window_id = ngDialog.open({closeByDocument: false,
                trapFocus: false,
                template: './html/component/deleteSku.html',
                disableAnimation: true,
                scope: $scope,
                controller: ['$scope', function ($scope) {
                        //确认删除商品
                        $scope.deleteSku_submit = function () {
                            ngDialog.close(window_id);
                            delete $scope._detail[index];
                            $scope.temp_detail.splice(arrindex, 1);
                            var lenindex =  temp_arr.length - 1 -(arrindex) ;
                            temp_arr.splice(lenindex, 1);
                            refresh_record();
                        };
                        //取消删除商品
                        $scope.deleteSku_close = function () {
                            ngDialog.close(window_id);
                        };
                    }]
            });
        };

        //编辑sku的数量
        $scope.edit = function (sku) {
            $scope.sku = sku;
            $scope.sku.e_num = sku.num;
            //增加一个临时数量存储
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/component/edit.html',
                disableAnimation: true,
                scope: $scope,
                trapFocus: false,
                preCloseCallback: function () {
		                    $scope.close_keyboard();//关闭小键盘
		                }
                        //                closeByDocument: false
            });
            //$scope.focus('input_num2');
            $scope.open_keyboard('sku.e_num');
        };
        //写一个刷新整个配货单
        var refresh_record = function () {
            var num = 0;
            var money = 0;
            $.each($scope._detail, function (index, n) {
                num = parseInt(num) + parseInt(n.num);
                money = parseFloat(money) + parseInt(n.num) * parseFloat(n.price);
                n.money = n.num * n.price;
            });
            $scope.record.num = num;
            $scope.record.money = money;
        };
        var goods_select_click_handler = function (sku) {
            //商品选择完毕之后，需要记录并且刷新整个页面实现一个动态的改变
			if($scope._detail[sku.SkuCode] != undefined){
				$scope._detail[sku.SkuCode].num = sku.num *1;
			}else{
				$scope._detail[sku.SkuCode] = {
					'index': sku.SkuCode,
					'record_code': $scope.record.record_code,
					'sku': sku.SkuCode,
					'property_name': sku.SkuPropertyName,
					'goods_code': sku.GoodsCode,
					'goods_name': sku.GoodsName,
					'goods_name_zh_tw': sku.GoodsName_zh_tw,
					'goods_name_en': sku.GoodsName_en,
					'color_code': sku.ColorCode,
					'size_code': sku.SizeCode,
					'zhek': 1,
					'num': sku.num,
					'price': new Number(sku.SkuPrice).toFixed(2),
					'money': parseInt(sku.num) * parseFloat(sku.SkuPrice)
				};
				temp_arr.push({'SkuCode':sku.SkuCode});
				$scope.temp_detail = temp_arr.concat();
				$scope.temp_detail.reverse();
			}
            //刷新整个配货单
            refresh_record();
            
            //清空搜索框
            $scope.input_keywords = '';
            ngDialog.close(window_id);
        };

        //弹框处理=======================================
        $scope.goods_select_click = function (sku) {
            $scope.sku = sku;
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/component/edit_num.html',
                disableAnimation: true,
                trapFocus: false,
                preCloseCallback: function () {
                    $scope.close_keyboard();//关闭小键盘
                },
                scope: $scope
                        //                closeByDocument: false
            });
            //$scope.focus('input_num1');
            $scope.open_keyboard('sku.num');
        };
        //选择商品填写数量
        $scope.save_num = function (sku) {
            var re = /^[1-9]+[0-9]*]*$/;
            if (sku.num == undefined) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EMPTY
                });
                return;
            } else if (sku.num <= 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY
                });
                return;
            } else if (!re.test(sku.num)) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                });
                return;
            }
            $scope.close_keyboard();//关闭小键盘
            goods_select_click_handler(sku);
            ngDialog.close(window_id);
        };
        //保存编辑
        $scope.save_edit = function (sku) {
            var re = /^[1-9]+[0-9]*]*$/;
            if (sku.e_num <= 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY
                });
                return;
            } else if (!re.test(sku.e_num)) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                });
                return;
            }
            $scope.close_keyboard();//关闭小键盘
            sku.num = sku.e_num;
            refresh_record();
            ngDialog.close(window_id);
        };
        $scope.clear = function (sku) {

            refresh_record();
            ngDialog.close(window_id);
        };
    }];

//出库单  jinhua.gu
var CunhuoChukuListCtrl = ['$scope', '$rootScope', '$location', 'ngDialog', 'chuku',
    function ($scope, $rootScope, $location, ngDialog, chuku) {
        $scope.curr = "chuku_list";
        var window_id = 0;
        $scope.filter = {};
        //查询条件
        $scope.filter.record_code = '';
        $scope.filter.record_time_start = '';
        $scope.filter.record_time_end = '';
        //查询
        $scope.search_chuku = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/cunhuo/chuku/chuku_select.html',
                disableAnimation: true,
                trapFocus: false,
                scope: $scope
                        //disableAnimation : true,
                        //closeByDocument: false
            });
        };


        //弹框+++++++++++++++++++++++++++++++++++++++++++++
        $scope.chuku_select = function (param) {
            if (param.record_time_start == '' || param.record_time_end == '') {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME,
                });
                return;
            }
            if (param.record_time_start > param.record_time_end) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.TIP_CASHIER_TITLE,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME_LIMIT,
                });
                return;
            }
            chuku.chuku_select(param).then(function (ret) {
                if (ret.data.status != 1) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.TIP_CASHIER_TITLE,
                        msg: $rootScope.language[ret.data.code]
                    });
                    return;
                } else if (ret.data.status == 1) {
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                        //第一个日期的
                    }
                    $scope.chuku_list = data;
                }
            }).catch(function (err) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
            ngDialog.close(window_id);
        };

        //重置
        $scope.clear = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
        };

        //私有方法++++++++++++++++++++++++++++++++++++++++++++++
        //获取终端退仓单据
        //从服务器搜索
        var search_api = function (param) {
            chuku.chuku_search_api(param).then(function (ret) {
                if (ret.data.status != 1) {
                    //更多按钮不显示
                    $scope.is_show = "";
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.TIP_CASHIER_TITLE,
                        msg: $rootScope.language[ret.data.code]
                    });
                    return;
                } else if (ret.data.status == 1) {
                    $scope.is_show = "true";
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                        //第一个日期的
                    }
                    $scope.chuku_list = data;
                }
            }).catch(function (err) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
        };

        //默认从服务器拿数据
        search_api({
            shop_code: $rootScope.current_shop.ShopCode
        });

        //加载更多++++++++++++++++++++++++++++++++++++++++
        //点击加载更多
        $scope.scoll = {};
        //滚动加载器
        $scope.scoll.busy = false;
        $scope.scoll.nextpage = function () {
            if ($scope.scoll.busy)
                return;
            baison_app.api.toast({
                msg: $rootScope.language.COMMON_LOADING
            });
            $scope.scoll.busy = true;
            var param = {};
            param.is_pre = 1;
            param.shop_code = $rootScope.current_shop.ShopCode;
            param.is_shop_stock_in = $scope.filter.fOrder;
            //判断是 以处理；未处理；还是全部
            if ($scope.chuku_list.length > 0) {
                param.day = $scope.chuku_list[$scope.chuku_list.length - 1]['key'];
            }
            chuku.chuku_search_api(param).then(function (ret) {
                if (ret.data.status == 1) {
                    for (i in ret.data.data) {
                        $scope.chuku_list.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.scoll.busy = false;
                } else if (ret.data.status == -1) {
                    baison_app.api.toast({
                        msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
                    });
                    $scope.scoll.busy = false;
                    $scope.is_show = "";
                }
            });
        };

    }];

//出库单详情 jinhua.gu
var CunhuoChukuDetailCtrl = ['$scope', '$rootScope', '$location', 'ngDialog', 'chuku', '$routeParams',
    function ($scope, $rootScope, $location, ngDialog, chuku, $routeParams) {
        $scope.curr = "chuku_list";
        var filter = {};
        filter.record_code = $routeParams.record_code;
        //出库单单据明细
        chuku.chuku_list_detail_search_by_code(filter).then(function (ret) {
            //是否需要出库操作
            if (ret.data.data.record.is_sure == 0) {
                $scope.is_chuku = "true";
            }
            $scope.chuku_list_detail = ret.data.data;
            $.each($scope.chuku_list_detail.record_detail, function (i, n) {
                $scope.chuku_list_detail.record_detail[i]['GoodsName'] = '';
                if (n.goods_name != '' && n.goods_name !== undefined) {
                    $scope.chuku_list_detail.record_detail[i]['GoodsName'] = n.goods_name;
                } else {
                    BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
                        $scope.chuku_list_detail.record_detail[i]['GoodsName'] = ret.GoodsName;
                    });
                }
            });
        });
        //出库操作
        $scope.flag = false;
        $scope.stock_out = function () {
            if ($scope.flag) {
                return;
            }
            $scope.flag = true;
            var param = {};
            param.record_code = $scope.chuku_list_detail.record.record_code;
            //ipos传一个操作员
            param.user_code = $rootScope.user.UserCode;
            //出库操作
            chuku.allocate_record_stock_out_detail(param).then(function (ret) {
                if (ret.data.status == 1) {
                    //库存相应的变化
                    $.each($scope.chuku_list_detail.record_detail, function (i, n) {
                        //库存数量增加
                        chuku.update_local_SkuNum(n.sku, n.num);
                    });
                    $scope.is_chuku = "";
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        msg: $rootScope.language[ret.data.code]
                    });
                }
            }).catch(function (msg) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
        };
        //关闭按钮
        $scope.come_back = function () {
            $location.path('/cunhuo/chuku');
        };
    }];
//调拨单
var CunhuoDiaoboListCtrl = ['$scope', '$rootScope', 'ngDialog', 'diaoBo',
    function ($scope, $rootScope, ngDialog, diaoBo) {
        $scope.curr = "diaobo_list";
        //查询条件
        $scope.filter = {};
        $scope.filter.record_code = '';
        $scope.filter.record_time_start = '';
        $scope.filter.record_time_end = '';
        var window_id = 0;

        $scope.active_switch_1 = true;
        $scope.active_switch_2 = false;
        //点击获取更多
        //点击加载更多
        $scope.scoll = {};
        //滚动加载器
        $scope.scoll.busy = false;
        $scope.scoll.nextpage = function () {
            if ($scope.scoll.busy)
                return;
            baison_app.api.toast({
                msg: $rootScope.language.COMMON_LOADING
            });
            $scope.scoll.busy = true;
            var param = {};
            param.is_pre = 1;
            if ($scope.active_switch_1 == true) {
                if (param.shift_out_store_code != undefined) {
                    delete param.shift_out_store_code;
                }
                param.shift_in_store_code = $rootScope.current_shop.ShopCode;
            } else if ($scope.active_switch_1 == false) {
                if (param.shift_in_store_code != undefined) {
                    delete param.shift_in_store_code;
                }
                param.shift_out_store_code = $rootScope.current_shop.ShopCode;
            }
            if ($scope.diaobo_list.length > 0) {
                param.day = $scope.diaobo_list[$scope.diaobo_list.length - 1]['key'];
            }
            diaoBo.diaobo_search_api(param).then(function (ret) {
                if (ret.data.status == 1) {
                    for (i in ret.data.data) {
                        $scope.diaobo_list.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.scoll.busy = false;
                } else {
                    baison_app.api.toast({
                        msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
                    });
                    $scope.is_show = "";
                }
            });
        };
        //从服务器获取数据
        var search_api = function (filter) {
            diaoBo.diaobo_search_api(filter).then(function (ret) {
                if (ret.data.status != 1) {
                    $scope.is_show = "";
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language[ret.data.code]
                    });
                    $scope.diaobo_list = [];
                    return;
                } else if (ret.data.status == 1) {
                    $scope.is_show = "true";
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                        //第一个日期的
                    }
                    $scope.diaobo_list = data;
                }
            }).catch(function (msg) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
        };
        //默认从服务器获取
        search_api({
            shift_in_store_code: $rootScope.current_shop.ShopCode,
        });
        //查询（按照时间查询）
        $scope.search = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/cunhuo/diaobo/diaobo_select.html',
                disableAnimation: true,
                scope: $scope,
                trapFocus: false
                        //                closeByDocument: false
            });
        };
        //重置按钮
        $scope.clear = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
        };
        //弹框处理==================================
        $scope.diaobo_select = function (filterData) {
            if (filterData.record_time_start == '' || filterData.record_time_end == '') {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME
                });
                return;
            }
            if (filterData.record_time_start > filterData.record_time_end) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME
                });
                return;
            }
            diaoBo.diaobo_select(filterData).then(function (ret) {
                if (ret.data.status != 1) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language[ret.data.code]
                    });
                    return;
                } else if (ret.data.status == 1) {
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.diaobo_list = data;
                }
            }).catch(function (err) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
            ngDialog.close(window_id);
        };

        //横调入
        $scope.diaoboRu = function () {
            $scope.active_switch_1 = true;
            $scope.active_switch_2 = false;
            search_api({
                shift_in_store_code: $rootScope.current_shop.ShopCode,
            });
        };


        //横调出
        $scope.diaoboChu = function () {
            $scope.active_switch_1 = false;
            $scope.active_switch_2 = true;
            search_api({
                shift_out_store_code: $rootScope.current_shop.ShopCode,
            });
        };
    }];

//调拨单据详细信息
var CunhuoDiaoboDetailCtrl = ['$scope', '$location', 'Print', '$routeParams', 'diaoBo', 'BaseGoods', '$rootScope',
    function ($scope, $location, Print, $routeParams, diaoBo, BaseGoods, $rootScope) {
        $scope.curr = "diaobo_list";
        var filter = {};
        filter.record_code = $routeParams.record_code;
        //is_execute执行按钮默认隐藏
        $scope.is_execute = "";
        //调拨单据明细(若是邻店向我要货的话，我就需要执行按钮，生成调出单)
        diaoBo.diaobo_list_detail_search_by_code(filter).then(function (ret) {
            if (ret.data.status == 1) {
                $scope.diaobo_list_detail = ret.data.data;
                if ($scope.diaobo_list_detail.stm_store_shift_record.shift_out_shop_code == $rootScope.current_shop.ShopCode) {
                    //执行操作，生成横调退仓单
                    if ($scope.diaobo_list_detail.stm_store_shift_record.is_execute == 0) {
                        $scope.is_execute = "true";
                        //执行操作
                        $scope.execute = function () {
                            diaoBo.diaobo_record_execute(filter.record_code).then(function (response) {
                                if (response.data.status == 1) {
                                    $scope.is_execute = "";
                                    baison_app.api.alert({msg: $rootScope.language[response.data.code]});
                                } else {
                                    baison_app.api.alert({msg: $rootScope.language[response.data.code]});
                                }
                            });
                        };
                    }
                }
                $.each($scope.diaobo_list_detail.stm_store_shift_record.stm_store_shift_record_detaill, function (i, n) {
                    $scope.diaobo_list_detail.stm_store_shift_record.stm_store_shift_record_detaill[i]['GoodsName'] = '';
                    if (n.goods_name != '' && n.goods_name !== undefined) {
                        $scope.diaobo_list_detail.stm_store_shift_record.stm_store_shift_record_detaill[i]['GoodsName'] = n.goods_name;
                    } else {
                        BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
                            $scope.diaobo_list_detail.stm_store_shift_record.stm_store_shift_record_detaill[i]['GoodsName'] = ret.GoodsName;
                        });
                    }

                });
            }
        });
        //返回按钮
        $scope.come_back = function () {
            $location.path('/cunhuo/diaobo_list');
        };

        //added by lqx maowei on 20170209 调拨申请详细打印事件
        $scope.to_print_diaoboshenqingdetail = function () {
            diaoBo.diaobo_list_detail_search_by_code(filter).then(function (ret) {
                if (ret.data.status == 1) {
                    var hendiaoshenqingdetail = ret.data.data;
                        Print.hendiaoshenqingdetail_print('', hendiaoshenqingdetail);
                }
            });
        };
    }];

//调拨新增
var CunhuoDiaoboAddCtrl = ['$scope', '$rootScope', '$location', 'timeStamp2String', 'PosUser', 'yaoHuo', 'diaoBo', 'ShopGetFriend','ThirdDev',
    function ($scope, $rootScope, $location, timeStamp2String, PosUser, yaoHuo, diaoBo, ShopGetFriend,ThirdDev) {
        $scope.curr = "diaobo_list";
        $scope.is_lqx = ThirdDev.is_lqx();
        $scope.filter = {};
        //新增配货单:营业员选择、退货类型选择、仓库
        $scope.filter.user_code_option = [];
        $scope.filter.shift_type_option = [];
        $scope.filter.shop_select_option = [];

        //输入商店代码进行查找邻店
        $scope.input_keywords = '';
        //营业员下拉
        var user_filter = {
            'ShopCode': $rootScope.current_shop.ShopCode,
            'UserStatus': 1
        };
        //单据退货类型下拉
        var record_type = {
            'record_type_property': 13
        };
        $scope.filter.record_code = yaoHuo.create_fast_bill_sn('store_shift');
        //生成单据编号
        $scope.filter.record_time = timeStamp2String(0, 'datetime');
        //日期
        //营业员下拉
        PosUser.get_list_by_cond(user_filter).then(function (ret) {
            $scope.filter.user_code_option = ret;
            //一个营业员数组
        });
        //单据类型下拉
        yaoHuo.record_type_list(record_type).then(function (ret) {
            $scope.filter.shift_type_option = ret;
            //单据类型下拉
        });
        //林清轩
        if (ThirdDev.is_lqx()) {//$rootScope.purview['\/cunhuo\/chuku'].show == 0
			//友好终端组
            ShopGetFriend().then(function (ret) {
                if (ret.data.status == 1) {
                    $.each(ret.data.data, function (i, n) {
                        if (n.friend_shop_code != $rootScope.current_shop.ShopCode) {
                            $scope.filter.shop_select_option.push({
                                'friend_shop_code': n.distributor_code,
                                'friend_shop_name': n.distributor_name
                            });
                        }
                    });
                }
            });
            
        } else {
            //友好终端组
            ShopGetFriend().then(function (ret) {
                if (ret.data.status == 1) {
                    $.each(ret.data.data, function (i, n) {
                        if (n.friend_shop_code != $rootScope.current_shop.ShopCode) {
                            $scope.filter.shop_select_option.push({
                                'friend_shop_code': n.friend_shop_code,
                                'friend_shop_name': n.friend_shop_name
                            });
                        }
                    });
                }
            });
        }

        //保存到本地
        $scope.save_local = function (filter) {
                if (filter.shift_type === undefined || filter.shift_type == null || filter.user_code === undefined || filter.user_code == null || filter.friend_shop_code === undefined || filter.friend_shop_code == null) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_INFO_NEED
                    });
                    return false;
                }
                $rootScope.local_diaobo_record = diaoBo.save_local(filter);
                $location.path('/cunhuo/diaobo_add_detail');

        };
        //重置按钮
        $scope.reset = function (filter) {
            filter.shift_type = filter.user_code = filter.friend_shop_code = undefined;
        };
    }];
//调拨新增详情
var CunhuoDiaoboAddDetailCtrl = ['$scope', '$rootScope', 'ngDialog', '$location', 'timeStamp2String', 'yaoHuo', 'diaoBo',
    function ($scope, $rootScope, ngDialog, $location, timeStamp2String, yaoHuo, diaoBo) {
        $scope.curr = "diaobo_list";
        var window_id = 0;
        $scope._detail = {};
        $scope.temp_detail=[];
        var temp_arr =[];
        //类似购物车
        $scope.input_keywords = '';
        //输入商品查询字段
        //刷新内容显示=================================
        //配货单进来需要刷新单据信息(保存的信息进行刷新)
        $scope.init_record = {};
        $scope.init_record = $rootScope.local_diaobo_record;
        $scope.init_record.num = 0;
        $scope.init_record.money = 0;

        var goods_select_click_handler = function (sku) {
            //商品选择完毕之后，需要记录并且刷新整个页面实现一个动态的改变
			if($scope._detail[sku.SkuCode] != undefined){
				$scope._detail[sku.SkuCode].num = sku.num*1;
			}else{
				$scope._detail[sku.SkuCode] = {
					'index': sku.SkuCode,
					'record_code': $scope.init_record.record_code,
					'sku': sku.SkuCode,
					//	'property_name' : sku.SkuPropertyName,
					'goods_code': sku.GoodsCode,
					'goods_name': sku.GoodsName,
					'goods_name_zh_tw': sku.GoodsName_zh_tw,
					'goods_name_en': sku.GoodsName_en,
					'color_code': sku.ColorCode,
					'size_code': sku.SizeCode,
					'zhek': 1.00,
					'num': sku.num,
					'price': new Number(sku.SkuPrice).toFixed(2),
					'money': parseInt(sku.num) * parseFloat(sku.SkuPrice)
				};
				temp_arr.push({'SkuCode':sku.SkuCode});
				$scope.temp_detail = temp_arr.concat();
				$scope.temp_detail.reverse();
			}
            
            //刷新整个配货单
            refresh_record();
            //清空搜索框
            $scope.input_keywords = '';
            ngDialog.close(window_id);
        };
        //商品sku查询
        $scope.search_goods = function (keywords) {
            var key = new String(keywords);
            if ('' == keywords || key.length < 3) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_NEED
                });
                return false;
            }
            diaoBo.sku_search_by_sku(keywords).then(function (ret) {
                if (ret.length == 0) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_SEARCH_GOODS
                    });
                    return false;
                }
                //只有一条数据时，直接添加
                if (ret.length == 1) {
                    $scope.sku = ret[0];
                    $scope.sku.num
                    window_id = ngDialog.open({closeByDocument: false,
                        template: './html/component/edit_num.html',
                        disableAnimation: true,
                        scope: $scope,
                        //                        closeByDocument: false
                        trapFocus: false,
                        preCloseCallback: function () {
		                    $scope.close_keyboard();//关闭小键盘
		                }
                    });
                    //$scope.focus('input_num1');
                    $scope.open_keyboard('sku.num');
                } else {
                    $scope.goods_select_data = ret;
                    window_id = ngDialog.open({closeByDocument: false,
                        template: './html/component/goods_select.html',
                        disableAnimation: true,
                        scope: $scope,
                        //                        closeByDocument: false
                        trapFocus: false
                    });
                }
            });
        };
        //删除一组sku
        $scope.del_sku = function (index,arrindex) {
            window_id = ngDialog.open({closeByDocument: false,
                trapFocus: false,
                template: './html/component/deleteSku.html',
                disableAnimation: true,
                scope: $scope,
                controller: ['$scope', function ($scope) {
                        //确认删除商品
                        $scope.deleteSku_submit = function () {
                            ngDialog.close(window_id);
                            delete $scope._detail[index];
                            $scope.temp_detail.splice(arrindex, 1);
                            var lenindex =  temp_arr.length - 1 -(arrindex) ;
                            temp_arr.splice(lenindex, 1);
                            refresh_record();
                        };
                        //取消删除商品
                        $scope.deleteSku_close = function () {
                            ngDialog.close(window_id);
                        };
                    }]
            });
        };

        //编辑sku的数量
        $scope.edit = function (sku) {
            $scope.sku = sku;
            $scope.sku.e_num = sku.num;
            //增加一个临时数量存储
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/component/edit.html',
                disableAnimation: true,
                scope: $scope,
                //                closeByDocument: false
                trapFocus: false,
                preCloseCallback: function () {
		                    $scope.close_keyboard();//关闭小键盘
		                }
            });
            //$scope.focus('input_num2');
            $scope.open_keyboard('sku.e_num');
        };
        //上传操作
        $scope.record_upload = function () {
            if (Object.keys($scope._detail).length == 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.MSG_WITHOUT_SELECT_GOODS
                });
                return;
            }
            var param = {};
            param.record = $scope.init_record;
            param.record_detail = $scope._detail;
            diaoBo.return_record_add_api(param).then(function (ret) {
                if (ret.data.status == 1) {
                    baison_app.api.toast({
                        msg: $rootScope.language.TIPS_CUNHUO_CONFIRM_SUCCESS
                    });
                    //如果成功就跳转到
                    $location.path('/cunhuo/diaobo_list');
                } else {
                    baison_app.api.toast({
                        msg: $rootScope.language[ret.data.code]
                    });
                }

            });
        };
        //写一个刷新整个配货单
        var refresh_record = function () {
            var num = 0;
            var money = 0;
            $.each($scope._detail, function (index, n) {
                num = parseInt(num) + parseInt(n.num);
                money = parseFloat(money) + parseInt(n.num) * parseFloat(n.price);
                n.money = n.num * n.price;
            });
            $scope.init_record.num = num;
            $scope.init_record.money = money;
        };
        //弹框处理=======================================
        //选择商品
        $scope.goods_select_click = function (sku) {
            $scope.sku = sku;
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/component/edit_num.html',
                disableAnimation: true,
                scope: $scope,
                //                closeByDocument: false
                trapFocus: false,
                preCloseCallback: function () {
		                    $scope.close_keyboard();//关闭小键盘
		                }
            });
            //$scope.focus('input_num1');
            $scope.open_keyboard('sku.num');
        };
        //选择商品填写数量
        $scope.save_num = function (sku) {
            var re = /^[1-9]+[0-9]*]*$/;
            if (sku.num == undefined) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EMPTY
                });
                return;
            } else if (sku.num <= 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY
                });
                return;
            } else if (!re.test(sku.num)) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                });
                return;
            }
            $scope.close_keyboard();//关闭小键盘
            goods_select_click_handler(sku);
            ngDialog.close(window_id);
        };
        //保存编辑
        $scope.save_edit = function (sku) {
            var re = /^[1-9]+[0-9]*]*$/;
            if (sku.e_num <= 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY
                });
                return;
            } else if (!re.test(sku.e_num)) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                });
                return;
            }
            $scope.close_keyboard();//关闭小键盘
            sku.num = sku.e_num;
            refresh_record();
            ngDialog.close(window_id);
        };
        $scope.clear = function () {
            refresh_record();
            ngDialog.close(window_id);
        };

    }];

//调出单
var CunhuoDiaoChuListCtrl = ['$scope', '$rootScope', 'ngDialog', 'diaoChu','ThirdDev',
    function ($scope, $rootScope, ngDialog, diaoChu,ThirdDev) {
        $scope.curr = "diaochu_list";
        $scope.is_lqx = ThirdDev.is_lqx();
        //查询条件
        $scope.filter = {};
        $scope.filter.record_code = '';
        $scope.filter.record_time_start = '';
        $scope.filter.record_time_end = '';
        var window_id = 0;
        //林清轩使用：0
        if (ThirdDev.is_lqx()) {//$rootScope.purview['\/DiaoboChuku'].show == 0
            //点击加载更多
            $scope.scoll = {};
            $scope.scoll.busy = false;
            $scope.scoll.nextpage = function () {
                if ($scope.scoll.busy)
                    return;
                baison_app.api.toast({
                    msg: $rootScope.language.COMMON_LOADING
                });
                $scope.scoll.busy = true;
                var param = {};
                param.is_pre = 1;
                param.shift_out_store_code = $rootScope.current_shop.ShopCode;
                if ($scope.diaochu_list.length > 0) {
                    param.day = $scope.diaochu_list[$scope.diaochu_list.length - 1]['key'];
                }
                diaoChu.diaochu_search_api(param).then(function (ret) {
                    if (ret.data.status == 1) {
                        for (i in ret.data.data) {
                            $scope.diaochu_list.push({
                                key: i,
                                value: ret.data.data[i]
                            });
                        }
                        $scope.scoll.busy = false;
                    } else if (ret.data.status == -1) {
                        baison_app.api.toast({
                            msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
                        });
                        $scope.is_show = "";
                    }
                });
            };
        } else {
            //点击加载更多
            $scope.scoll = {};
            $scope.scoll.busy = false;
            $scope.scoll.nextpage = function () {
                if ($scope.scoll.busy)
                    return;
                baison_app.api.toast({
                    msg: $rootScope.language.COMMON_LOADING
                });
                $scope.scoll.busy = true;
                var param = {};
                param.is_pre = 1;
                param.shop_code = $rootScope.current_shop.ShopCode;
                if ($scope.diaochu_list.length > 0) {
                    param.day = $scope.diaochu_list[$scope.diaochu_list.length - 1]['key'];
                }
                diaoChu.shift_out_search_group_data(param).then(function (ret) {
                    if (ret.data.status == 1) {
                        for (i in ret.data.data) {
                            $scope.diaochu_list.push({
                                key: i,
                                value: ret.data.data[i]
                            });
                        }
                        $scope.scoll.busy = false;
                    } else if (ret.data.status == -1) {
                        baison_app.api.toast({
                            msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
                        });
                        $scope.is_show = "";
                    }
                });
            };
        }

        //查询
        $scope.search = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/cunhuo/diaochu/diaochu_select.html',
                disableAnimation: true,
                scope: $scope,
                //                closeByDocument: false
                trapFocus: false
            });
        };
        //重置按钮
        $scope.clear = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
        };
        //从服务器获取数据(林清轩)
        //林清轩
        if (ThirdDev.is_lqx()) {//$rootScope.purview['\/DiaoboChuku'].show == 0
            var search_api = function (filter) {
                diaoChu.diaochu_search_api(filter).then(function (ret) {
                    if (ret.data.status != 1) {
                        $scope.is_show = "";
                        baison_app.api.toast({
                            buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                            msg: $rootScope.language[ret.data.code]
                        });
                        return;
                    } else if (ret.data.status == 1) {
                        $scope.is_show = "true";
                        var data = [];
                        for (i in ret.data.data) {
                            data.push({
                                key: i,
                                value: ret.data.data[i]
                            });
                        }
                        $scope.diaochu_list = data;
                    }
                }).catch(function (msg) {
                    baison_app.api.toast({
                        msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                    });
                });
            };
            search_api({
                shift_out_store_code: $rootScope.current_shop.ShopCode
            });
        } else {
            //lite地址使用
            var search_api = function (filter) {
                diaoChu.shift_out_search_group_data(filter).then(function (ret) {
                    if (ret.data.status != 1) {
                        $scope.is_show = "";
                        baison_app.api.toast({
                            buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                            msg: $rootScope.language[ret.data.code]
                        });
                        return;
                    } else if (ret.data.status == 1) {
                        $scope.is_show = "true";
                        var data = [];
                        for (i in ret.data.data) {
                            data.push({
                                key: i,
                                value: ret.data.data[i]
                            });
                        }
                        $scope.diaochu_list = data;
                    }
                }).catch(function (msg) {
                    baison_app.api.toast({
                        msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                    });
                });
            };
            search_api({
                shop_code: $rootScope.current_shop.ShopCode
            });
        }

        //默认一进来就执行
        //弹框处理================================
        $scope.diaochu_select = function (filterData) {
            if (filterData.record_time_start == '' || filterData.record_time_end == '') {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME
                });
                return;
            }
            if (filterData.record_time_start > filterData.record_time_end) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME_LIMIT
                });
                return;
            }
            //0:林清轩
            if (ThirdDev.is_lqx()) {//$rootScope.purview['\/DiaoboChuku'].show == 0
                diaoChu.diaochu_select(filterData).then(function (ret) {
                    if (ret.data.status != 1) {
                        baison_app.api.toast({
                            buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                            title: $rootScope.language.COMMON_TITLE_HINT,
                            msg: $rootScope.language[ret.data.code]
                        });
                        return;
                    } else if (ret.data.status == 1) {
                        var data = [];
                        for (i in ret.data.data) {
                            data.push({
                                key: i,
                                value: ret.data.data[i]
                            });
                        }
                        $scope.diaochu_list = data;
                    }
                }).catch(function (err) {
                    baison_app.api.toast({
                        msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                    });
                });
            } else {
                diaoChu.shift_out_select(filterData).then(function (ret) {
                    if (ret.data.status != 1) {
                        baison_app.api.toast({
                            buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                            title: $rootScope.language.COMMON_TITLE_HINT,
                            msg: $rootScope.language[ret.data.code]
                        });
                        return;
                    } else if (ret.data.status == 1) {
                        var data = [];
                        for (i in ret.data.data) {
                            data.push({
                                key: i,
                                value: ret.data.data[i]
                            });
                        }
                        $scope.diaochu_list = data;
                    }
                }).catch(function (err) {
                    baison_app.api.toast({
                        msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                    });
                });
            }
            ngDialog.close(window_id);
        };
    }];

//调出单据详细信息
var CunhuoDiaoChuDetailCtrl = ['$scope', '$location', 'Print', '$routeParams', 'diaoChu', 'BaseGoods', '$rootScope','ThirdDev',
    function ($scope, $location, Print, $routeParams, diaoChu, BaseGoods, $rootScope,ThirdDev) {
        $scope.curr = "diaochu_list";
        $scope.is_lqx = ThirdDev.is_lqx();
        var filter = {};
        filter.record_code = $routeParams.record_code;
        //林清轩横调出库
        if (ThirdDev.is_lqx()) {  //$rootScope.purview['\/DiaoboChuku'].show == 0
            diaoChu.diaochu_list_detail_search_by_code(filter).then(function (ret) {
                if (ret.data.data.stm_store_shift_record.is_sure == 1 && ret.data.data.stm_store_shift_record.is_cancel != 1 && ret.data.data.stm_store_shift_record.is_shift_out == 0) {
                    $scope.is_chuku = "true";
                }
                $scope.diaochu_list_detail = ret.data.data;
                $.each($scope.diaochu_list_detail.stm_store_shift_record.stm_store_shift_record_detaill, function (i, n) {
                    $scope.diaochu_list_detail.stm_store_shift_record.stm_store_shift_record_detaill[i]['GoodsName'] = '';
                    BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
                        $scope.diaochu_list_detail.stm_store_shift_record.stm_store_shift_record_detaill[i]['GoodsName'] = ret.GoodsName;
                    });
                });
            });
        } else {
            //ipos横调出库
            diaoChu.shift_out_detail(filter).then(function (ret) {
                if (ret.data.data.stm_store_shift_record.is_sure == 0) {
                    $scope.is_chuku = "true";
                }
                $scope.diaochu_list_detail = ret.data.data;
                $.each($scope.diaochu_list_detail.stm_store_shift_record.stm_store_shift_record_detaill, function (i, n) {
                    $scope.diaochu_list_detail.stm_store_shift_record.stm_store_shift_record_detaill[i]['GoodsName'] = '';
                    if (n.goods_name != '' && n.goods_name !== undefined) {
                        $scope.diaochu_list_detail.stm_store_shift_record.stm_store_shift_record_detaill[i]['GoodsName'] = n.goods_name;
                    } else {
                        BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
                            $scope.diaochu_list_detail.stm_store_shift_record.stm_store_shift_record_detaill[i]['GoodsName'] = ret.GoodsName;
                        });
                    }
                });
            });
        }

        //出库操作
        $scope.stock_out = function () {
            if ($rootScope.purviewCheckChange('\/CunhuoDiaoChuDetailCtrl:stock_out') == 0) {
                return;
            }
            var param = {};
            //ipos:
            if (!ThirdDev.is_lqx()) { //$rootScope.purview['\/DiaoboChuku'].show == 1
                param.record_code = filter.record_code;
                //ipos传一个操作员
                param.user_code = $rootScope.user.UserCode;
            } else {
                //林清轩
                param.record_code = $scope.diaochu_list_detail.stm_store_shift_record.record_code;
                param.user_code = $rootScope.user.UserCode;
            }
            diaoChu.store_shift_record_store_out(param).then(function (ret) {
                if (ret.data.status == 1) {
                    $.each($scope.diaochu_list_detail.stm_store_shift_record.stm_store_shift_record_detaill, function (i, n) {
                        //库存相应减少
                        diaoChu.update_local_SkuNum(n.sku, n.num);
                    });
                    $scope.is_chuku = "";
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language[ret.data.code]
                    });
                }else{
                	baison_app.api.toast({
                        msg:ret.data.message
                    });
                }
            }).catch(function (msg) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
        };
        //返回按钮
        $scope.come_back = function () {
            $location.path('/cunhuo/diaochu_list');
        };

        //added by lqx maowei on 20170112 横调出货单打印
        $scope.to_print_hendiaochuku = function () {
            if (ThirdDev.is_lqx()) {  //$rootScope.purview['\/DiaoboChuku'].show == 0
                diaoChu.diaochu_list_detail_search_by_code(filter).then(function (ret) {
                    var hendiaochukudetail = ret.data.data;
                    Print.hendiaochukudetail_print('', hendiaochukudetail);                 
                });
            } else {
                //ipos横调出库
                diaoChu.shift_out_detail(filter).then(function (ret) {
                    var hendiaochukudetail = ret.data.data;
                    Print.hendiaochukudetail_print('', hendiaochukudetail);
                });
            }
        };
    }];

//调入单
var CunhuoDiaoRuListCtrl = ['$scope', '$rootScope', 'ngDialog', 'diaoRu','ThirdDev',
    function ($scope, $rootScope, ngDialog, diaoRu,ThirdDev) {
        $scope.curr = "diaoru_list";
        $scope.is_lqx = ThirdDev.is_lqx();
        //查询条件
        $scope.filter = {};
        $scope.filter.record_code = '';
        $scope.filter.record_time_start = '';
        $scope.filter.record_time_end = '';
        var window_id = 0;
        //从服务器获取数据（林清轩）
        if (ThirdDev.is_lqx()) {  //$rootScope.purview['\/DiaoboRuku'].show == 0
            var search_api = function (filter) {
                diaoRu.diaoru_search_api(filter).then(function (ret) {
                    if (ret.data.status != 1) {
                        $scope.is_show = "";
                        baison_app.api.toast({
                            buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                            title: $rootScope.language.COMMON_TITLE_HINT,
                            msg: $rootScope.language[ret.data.code]
                        });
                        return;
                    } else if (ret.data.status == 1) {
                        $scope.is_show = "true";
                        var data = [];
                        for (i in ret.data.data) {
                            data.push({
                                key: i,
                                value: ret.data.data[i]
                            });
                        }
                        $scope.diaoru_list = data;
                    }
                }).catch(function (msg) {
                    baison_app.api.toast({
                        msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                    });
                });
            };
            search_api({
                shift_in_store_code: $rootScope.current_shop.ShopCode
            });
        } else {
            //lite地址
            var search_api = function (filter) {
                diaoRu.shift_in_search_group_data(filter).then(function (ret) {
                    if (ret.data.status != 1) {
                        $scope.is_show = "";
                        baison_app.api.toast({
                            buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                            title: $rootScope.language.COMMON_TITLE_HINT,
                            msg: $rootScope.language[ret.data.code]
                        });
                        return;
                    } else if (ret.data.status == 1) {
                        $scope.is_show = "true";
                        var data = [];
                        for (i in ret.data.data) {
                            data.push({
                                key: i,
                                value: ret.data.data[i]
                            });
                        }
                        $scope.diaoru_list = data;
                    }
                }).catch(function (msg) {
                    baison_app.api.toast({
                        msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                    });
                });
            };
            search_api({
                shop_code: $rootScope.current_shop.ShopCode
            });
        }
        //lqx
        if (ThirdDev.is_lqx()) { //$rootScope.purview['\/DiaoboRuku'].show == 0
            //点击加载更多
            $scope.scoll = {};
            $scope.scoll.busy = false;
            $scope.scoll.nextpage = function () {
                if ($scope.scoll.busy)
                    return;
                baison_app.api.toast({
                    msg: $rootScope.language.COMMON_LOADING
                });
                $scope.scoll.busy = true;
                var param = {};
                param.is_pre = 1;
                param.shift_in_store_code = $rootScope.current_shop.ShopCode;
                if ($scope.diaoru_list.length > 0) {
                    param.day = $scope.diaoru_list[$scope.diaoru_list.length - 1]['key'];
                }
                diaoRu.diaoru_search_api(param).then(function (ret) {
                    if (ret.data.status == 1) {
                        for (i in ret.data.data) {
                            $scope.diaoru_list.push({
                                key: i,
                                value: ret.data.data[i]
                            });
                        }
                        $scope.scoll.busy = false;
                    } else if (ret.data.status == -1) {
                        baison_app.api.toast({
                            msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
                        });
                        $scope.is_show = "";
                    }
                });
            };

        } else {
            //点击加载更多
            $scope.scoll = {};
            $scope.scoll.busy = false;
            $scope.scoll.nextpage = function () {
                if ($scope.scoll.busy)
                    return;
                baison_app.api.toast({
                    msg: $rootScope.language.COMMON_LOADING
                });
                $scope.scoll.busy = true;
                var param = {};
                param.is_pre = 1;
                param.shop_code = $rootScope.current_shop.ShopCode;
                if ($scope.diaoru_list.length > 0) {
                    param.day = $scope.diaoru_list[$scope.diaoru_list.length - 1]['key'];
                }
                diaoRu.shift_in_search_group_data(param).then(function (ret) {
                    if (ret.data.status == 1) {
                        for (i in ret.data.data) {
                            $scope.diaoru_list.push({
                                key: i,
                                value: ret.data.data[i]
                            });
                        }
                        $scope.scoll.busy = false;
                    } else if (ret.data.status == -1) {
                        baison_app.api.toast({
                            msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
                        });
                        $scope.is_show = "";
                    }
                });
            };

        }


        //查询
        $scope.search = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/cunhuo/diaoru/diaoru_select.html',
                disableAnimation: true,
                scope: $scope,
                //                closeByDocument: false
                trapFocus: false
            });
        };
        //重置按钮
        $scope.clear = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
        };
        //弹框处理================================
        $scope.diaoru_select = function (filterData) {
            if (filterData.record_time_start == '' || filterData.record_time_end == '') {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME
                });
                return;
            }
            if (filterData.record_time_start > filterData.record_time_end) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME_LIMIT
                });
                return;
            }
            //0:林清轩
            if (ThirdDev.is_lqx()) { //$rootScope.purview['\/DiaoboRuku'].show == 0
                diaoRu.diaoru_select(filterData).then(function (ret) {
                    if (ret.data.status != 1) {
                        baison_app.api.toast({
                            buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                            msg: $rootScope.language[ret.data.code]
                        });
                        return;
                    } else if (ret.data.status == 1) {
                        var data = [];
                        for (i in ret.data.data) {
                            data.push({
                                key: i,
                                value: ret.data.data[i]
                            });
                        }
                        $scope.diaoru_list = data;
                    }
                }).catch(function (err) {
                    baison_app.api.toast({
                        msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                    });
                });
            } else {
                diaoRu.shift_in_select(filterData).then(function (ret) {
                    if (ret.data.status != 1) {
                        baison_app.api.toast({
                            buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                            msg: $rootScope.language[ret.data.code]
                        });
                        return;
                    } else if (ret.data.status == 1) {
                        var data = [];
                        for (i in ret.data.data) {
                            data.push({
                                key: i,
                                value: ret.data.data[i]
                            });
                        }
                        $scope.diaoru_list = data;
                    }
                }).catch(function (err) {
                    baison_app.api.toast({
                        msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                    });
                });
            }

            ngDialog.close(window_id);
        };
    }];

//调入单据细节
var CunhuoDiaoRuDetailCtrl = ['$scope', '$rootScope', 'Print', '$routeParams', '$location', 'diaoRu', 'BaseGoods','ThirdDev',
    function ($scope, $rootScope, Print, $routeParams, $location, diaoRu, BaseGoods,ThirdDev) {
        $scope.curr = "diaoru_list";
        $scope.is_lqx = ThirdDev.is_lqx();
        var filter = {};
        filter.record_code = $routeParams.record_code;
        //林清轩横调入库
        if (ThirdDev.is_lqx()) { //$rootScope.purview['\/DiaoboRuku'].show == 0
            diaoRu.diaoru_list_detail_search_by_code(filter).then(function (ret) {
                if (ret.data.data.stm_store_shift_record.is_sure == 1 && ret.data.data.stm_store_shift_record.is_cancel != 1 && ret.data.data.stm_store_shift_record.is_shift_out == 1 && ret.data.data.stm_store_shift_record.is_shift_in == 0) {
                    $scope.is_ruku = "true";
                }
                $scope.diaoru_list_detail = ret.data.data;
                $.each($scope.diaoru_list_detail.stm_store_shift_record.stm_store_shift_record_detaill, function (i, n) {
                    $scope.diaoru_list_detail.stm_store_shift_record.stm_store_shift_record_detaill[i]['GoodsName'] = '';
                    BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
                        $scope.diaoru_list_detail.stm_store_shift_record.stm_store_shift_record_detaill[i]['GoodsName'] = ret.GoodsName;
                    });
                });
            });
        } else {
            //ipos
            diaoRu.shift_in_detail(filter).then(function (ret) {
                if (ret.data.data.stm_store_shift_record.is_sure == 0) {
                    $scope.is_ruku = "true";
                }
                $scope.diaoru_list_detail = ret.data.data;
                $.each($scope.diaoru_list_detail.stm_store_shift_record.stm_store_shift_record_detaill, function (i, n) {
                    $scope.diaoru_list_detail.stm_store_shift_record.stm_store_shift_record_detaill[i]['GoodsName'] = '';
                    if (n.goods_name != '' && n.goods_name !== undefined) {
                        $scope.diaoru_list_detail.stm_store_shift_record.stm_store_shift_record_detaill[i]['GoodsName'] = n.goods_name;
                    } else {
                        BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
                            $scope.diaoru_list_detail.stm_store_shift_record.stm_store_shift_record_detaill[i]['GoodsName'] = ret.GoodsName;
                        });
                    }

                });
            });
        }

        //入库操作
        $scope.stock_in = function () {
            if ($rootScope.purviewCheckChange('\/CunhuoDiaoRuDetailCtrl\/stock_in') == 0) {
                return;
            }
            var param = {};
            //ipos
            if (!ThirdDev.is_lqx()) {//$rootScope.purview['\/DiaoboRuku'].show == 1
                param.record_code = filter.record_code;
                //ipos传一个操作员
                param.user_code = $rootScope.user.UserCode;
            } else {
                //林清轩
                param.record_code = $scope.diaoru_list_detail.stm_store_shift_record.record_code;
                param.user_code = $rootScope.user.UserCode;
            }
            //入库操作
            diaoRu.store_shift_record_store_in(param).then(function (ret) {
                if (ret.data.status == 1) {
                    //库存相应的进行变化
                    $.each($scope.diaoru_list_detail.stm_store_shift_record.stm_store_shift_record_detaill, function (i, n) {
                        //库存增加
                        diaoRu.update_local_SkuNum(n.sku, n.num);
                    });
                    $scope.is_ruku = "";
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        msg: $rootScope.language[ret.data.code]
                    });
                }else{
                	baison_app.api.toast({
                        msg:ret.data.message
                    });
                }
            }).catch(function (msg) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
        };

        //added by lqx maowei on 20170119 横调入库打印
        $scope.to_print_hendiaoruku = function () {
            if (ThirdDev.is_lqx()) { //$rootScope.purview['\/DiaoboRuku'].show == 0
                diaoRu.diaoru_list_detail_search_by_code(filter).then(function (ret) {
                    var hendiaorukudetail = ret.data.data;
                    Print.hendiaorukudetail_print('', hendiaorukudetail);
                });
            } else {
                //ipos
                diaoRu.shift_in_detail(filter).then(function (ret) {
                    var hendiaorukudetail = ret.data.data;
                    Print.hendiaorukudetail_print('', hendiaorukudetail);
                });
            }
        }

        //返回按钮
        $scope.come_back = function () {
            $location.path('/cunhuo/diaoru_list');
        };
    }];

//盘点任务单列表 jinhua.gu
var CunhuoPanDianTaskListCtrl = ['$scope', '$rootScope', 'ngDialog', 'panDian',
    function ($scope, $rootScope, ngDialog, panDian) {
        $scope.curr = "pandianTask_list";
        //查询条件
        $scope.filter = {};
        $scope.filter.record_code = '';
        $scope.filter.record_time_start = '';
        $scope.filter.record_time_end = '';
        var window_id = 0;
        //点击加载更多
        $scope.scoll = {};
        $scope.scoll.busy = false;
        $scope.scoll.nextpage = function () {
            if ($scope.scoll.busy)
                return;
            baison_app.api.toast({
                msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
            });
            $scope.scoll.busy = true;
            var param = {};
            param.is_pre = 1;
            param.store_code = $rootScope.current_shop.ShopCode;
            if ($scope.pandianTask_list.length > 0) {
                param.day = $scope.pandianTask_list[$scope.pandianTask_list.length - 1]['key'];
            }
            panDian.pandianTask_search_api(param).then(function (ret) {
                if (ret.data.status == 1) {
                    for (i in ret.data.data) {
                        $scope.pandianTask_list.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.scoll.busy = false;
                } else if (ret.data.status == -1) {
                    baison_app.api.toast({
                        msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
                    });
                    $scope.is_show = "";
                }
            });
        };
        //从服务器获取数据
        var search_api = function (filter) {
            panDian.pandianTask_search_api(filter).then(function (ret) {
                if (ret.data.status != 1) {
                    $scope.is_show = "";
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language[ret.data.code]
                    });
                    return;
                } else if (ret.data.status == 1) {
                    $scope.is_show = "true";
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.pandianTask_list = data;
                }
            }).catch(function (msg) {
                baison_app.api.toast({
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
                });
            });
        };
        search_api({
            store_code: $rootScope.current_shop.ShopCode
        });
        //查询
        $scope.search = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/cunhuo/pandian/pandian_select.html',
                disableAnimation: true,
                scope: $scope,
                //                closeByDocument: false
                trapFocus: false
            });
        };
        //重置按钮
        $scope.clear = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
        };
        //弹框处理================================
        $scope.pandian_select = function (filterData) {
            if (filterData.record_time_start == '' || filterData.record_time_end == '') {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME
                });
                return;
            }
            if (filterData.record_time_start > filterData.record_time_end) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME_LIMIT
                });
                return;
            }
            panDian.pandianTask_select(filterData).then(function (ret) {
                if (ret.data.status != 1) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language[ret.data.code]
                    });
                    return;
                } else if (ret.data.status == 1) {
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.pandianTask_list = data;
                }
            }).catch(function (err) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
            ngDialog.close(window_id);
        };
    }];
//盘点任务单单据明细  jinhua.gu
var CunhuoPanDianTaskDetailCtrl = ['$scope', '$routeParams', '$location', '$rootScope', 'ngDialog', 'panDian', 'yaoHuo', 'timeStamp2String', 'BaseGoods',
    function ($scope, $routeParams, $location, $rootScope, ngDialog, panDian, yaoHuo, timeStamp2String, BaseGoods) {
        $scope.curr = "pandianTask_list";
        var window_id = 0;
        //默认进来：按钮都有:执行、预盈亏、确认、盈亏
        $scope.zx = "";
        $scope.yyk = "";  
        $scope.qr = "";    
        $scope.yk = "";
        $scope.cp = "";
        $scope.add = "";   
        //盘点单所需参数对象
        var stock = {};
        var filter = {};
        filter.record_code = $routeParams.record_code;
        //获取盘点任务单单据明细
        panDian.pandianTask_list_detail_search_by_code(filter).then(function (ret) {
            if (ret.data.status == 1) {
                $scope.pandianTask_list_detail = ret.data.data;                
                //若是未执行的需要执行
                if ($scope.pandianTask_list_detail.record.is_execute == 0) {
                    $scope.zx = "true";
                    $scope.yyk = "";
                    $scope.qr = "";
                    $scope.yk = "";
                    $scope.cp = "";
                    $scope.add = "";
                }else{
                	$scope.zx = "";
                    $scope.yyk = "true";
			        $scope.qr = "true";
			        $scope.yk = "";
			        $scope.cp = "";
			        $scope.add = "true";
                }
                
                //判断是否：预盈亏、确定、盈亏
                //预盈亏之后:预盈亏、确定、新增盘点单显示，盈亏不显示
                if ($scope.pandianTask_list_detail.record.is_pre_profit_and_loss == 1) {
                    $scope.yyk = "true";
                    $scope.qr = "true";
                    $scope.yk = "";
                    $scope.add = "true";
                }
                //确认：重盘/盈亏、终止显示
                if ($scope.pandianTask_list_detail.record.is_sure == 1) {
                    $scope.qr = "";
                    $scope.cp = "true";
                    $scope.yk = "true";
                    $scope.add = "";
                    $scope.yyk = "";
                }
                //盈亏成功之后：所有按钮隐藏
                if ($scope.pandianTask_list_detail.record.is_profit_and_loss == 1) {
                    $scope.yyk = "";
                    $scope.qr = "";
                    $scope.yk = "";
                    $scope.cp = "";
                    $scope.add = "";
                }
                //判断是否是终止
                if($scope.pandianTask_list_detail.record.is_stop == 1){
                	$scope.zx = "";
                    $scope.yyk = "";
                    $scope.qr = "";
                    $scope.yk = "";
                    $scope.cp = "";
                    $scope.add = "";
                }
                //如果操作结束了，就隐藏全部
                if ($scope.pandianTask_list_detail.record.is_profit_and_loss == 1 && $scope.pandianTask_list_detail.record.is_pre_profit_and_loss == 1
                        && $scope.pandianTask_list_detail.record.is_sure == 1) {
                    $scope.yyk = "";
                    $scope.qr = "";
                    $scope.yk = "";
                    $scope.cp = "";
                    $scope.add = "";
                }
                $.each($scope.pandianTask_list_detail.record_detail, function (i, n) {
                    $scope.pandianTask_list_detail.record_detail[i]['GoodsName'] = n.goods_name;
                });
            }
        });
        //关闭按钮
        $scope.come_back = function () {
            $location.path('/cunhuo/pandianTask_list');
        };
        //执行按钮(未执行的盘点任务单)
        $scope.do_act = function (record_code) {
            panDian.pandianTask_do_act(record_code).then(function (response) {
                if (response.data.status == 1) {
                    $scope.zx = "";
                    $scope.yyk = "true";
                    $scope.qr = "true";
                    $scope.add = "true";
                    baison_app.api.alert({msg: $rootScope.language[response.data.code]});
                    $location.path('/cunhuo/pandianTask_list');
                } else {
                    baison_app.api.alert({msg: $rootScope.language[response.data.code]});
                }
            });
        };
        //新增盘点单
        $scope.add_pandianRecord = function (relation_code, stock_type, brand_code, brand_name) {
            //判断任务单状态：未执行或者已执行已终止就不能新增
            if ($scope.pandianTask_list_detail.record.is_execute == 0) {
                baison_app.api.toast({msg: '任务单未执行'});
                return;
            }
            if ($scope.pandianTask_list_detail.record.is_stop == 1) {
                baison_app.api.toast({msg: '该任务单已被终止，不能新增盘点单'});
                return;
            }
            //若是商品级盘点默认就只有手动录入
            if (stock_type == 1) {
                stock.status = 0;
                //盘点类型:0表示全盘   1表示商品级盘点
                stock.stock_type = stock_type;
                //盘点单号
                stock.record_code = yaoHuo.create_fast_bill_sn('pandian');
                //任务单号
                stock.relation_code = relation_code;
                //盘点日期
                stock.record_time = timeStamp2String(0, 'datetime');
                //店铺代码
                stock.store_code = $rootScope.current_shop.ShopCode;
                //操作用户
                stock.user_code = $rootScope.user.UserCode;
                //品牌代码
                stock.brand_code = brand_code;
                //品牌名称
                stock.brand_name = brand_name;
                //新增盘点单
                panDian.add_take_stock_record(stock).then(function (ret) { 
                    if (ret.data.status == 1) {
                        baison_app.api.alert({
                            msg: $rootScope.language[ret.data.code]
                        });
                        //新增成功跳转到增加详情
                        $rootScope.local_pandian = stock;
                        $location.path('/cunhuo/pandian_add_detail');
                    } else {
                        baison_app.api.alert({
                            msg: $rootScope.language[ret.data.code]
                        });
                    }
                });
            } else if (stock_type == 0) {
                //全盘有自动录入功能
                window_id = ngDialog.open({closeByDocument: false,
                    template: './html/cunhuo/pandian/automatic_goods.html',
                    disableAnimation: true,
                    scope: $scope,
                    //                closeByDocument: false
                    trapFocus: false,
                    controller: ['$scope', 'yaoHuo', 'timeStamp2String', '$rootScope', 'panDian', '$location', 'ngDialog',
                        function ($scope, yaoHuo, timeStamp2String, $rootScope, panDian, $location, ngDialog) {
                            $scope.pandian = {};
                            $scope.pandian.status = 0;
                            //是都自动录入商品
                            $scope.confirmSubmit = function (data) {
                                stock.status = data.status;
                                //盘点类型:0表示全盘   1表示商品级盘点
                                stock.stock_type = stock_type;
                                //盘点单号
                                stock.record_code = yaoHuo.create_fast_bill_sn('pandian');
                                //任务单号
                                stock.relation_code = relation_code;
                                //盘点日期
                                stock.record_time = timeStamp2String(0, 'datetime');
                                //店铺代码
                                stock.store_code = $rootScope.current_shop.ShopCode;
                                //操作用户
                                stock.user_code = $rootScope.user.UserCode;
                                //品牌代码
                                stock.brand_code = brand_code;
                                //品牌名称
                                stock.brand_name = brand_name;
                                //新增
                                panDian.add_take_stock_record(stock).then(function (ret) {
                                    if (ret.data.status == 1) {
                                        baison_app.api.alert({msg: $rootScope.language[ret.data.code]});
                                        //新增成功跳转到增加详情
                                        $rootScope.local_pandian = stock;
                                        $location.path('/cunhuo/pandian_add_detail');
                                    } else {
                                        baison_app.api.alert({msg: $rootScope.language[ret.data.code]});
                                    }
                                    ngDialog.close(window_id);
                                });

                            };
                        }]
                });
                ngDialog.close(window_id);
            }

        };
        //重盘
        $scope.rePandian = function (record_code) {
            panDian.pandianTask_cp(record_code).then(function (response) {
                if (response.data.status == 1) {
                    baison_app.api.alert({msg: $rootScope.language[response.data.code]});
                    $scope.yyk = "true";
                    $scope.qr = "true";
                    $scope.yk = "true";
                    //重盘之后：盘点任务单应该变成未执行
                    $scope.zx = "true";
                    //将本地所有任务单下的盘点单上传状态is_upload = 0
                    panDian.update_stock_record_unupload(record_code);
                } else {
                    baison_app.api.alert({msg: $rootScope.language[response.data.code]});
                }
            });
        };
        //预盈亏
        $scope.is_pre_profit_and_loss = function (record_code) {
            panDian.pandianTask_profit_and_loss_by_app(record_code).then(function (response) {
                if (response.data.status == 1) {
                    baison_app.api.alert({msg: $rootScope.language[response.data.code]});
                    //预盈亏、确定、新增盘点单显示，盈亏不显示
                    $scope.yyk = "true";
                    $scope.qr = "true";
                    $scope.yk = "";
                    $scope.add = "true";
                    $scope.cp = "";
                } else {
                    baison_app.api.alert({msg: $rootScope.language[response.data.code]});
                }
            });
        };

        //确认
        $scope.confirm = function (record_code) {
            panDian.pandianTask_confirm(record_code).then(function (response) {
                if (response.data.status == 1) {
                    baison_app.api.alert({msg: $rootScope.language[response.data.code]});
                    //重盘/盈亏、终止显示
                    $scope.qr = "";
                    $scope.cp = "true";
                    $scope.yk = "true";
                    $scope.yyk = "";
                    $scope.add = "";
                } else {
                    baison_app.api.alert({msg: $rootScope.language[response.data.code]});
                }
            });
        };

        //盈亏
        $scope.profit_and_loss = function (record_code) {
            panDian.pandianTask_profit_and_loss(record_code).then(function (response) {
                if (response.data.status == 1) {
                    baison_app.api.alert({msg: $rootScope.language[response.data.code]});
                    //所有按钮隐藏
                    $scope.yk = "";
                    $scope.yyk = "";
                    $scope.qr = "";
                    $scope.yk = "";
                    $scope.cp = "";
                    $scope.add = "";
                } else {
                    baison_app.api.alert({msg: $rootScope.language[response.data.code]});
                }
            });
        };


    }]


//盘点单
var CunhuoPanDianListCtrl = ['$q', '$scope', '$rootScope', 'ngDialog', 'panDian','timeStamp2String','Print','dbGetOne',
    function ($q, $scope, $rootScope, ngDialog, panDian,timeStamp2String,Print,dbGetOne) {
        $scope.curr = "pandian_list";
        //查询条件
        $scope.filter = {};
        $scope.filter.record_code = '';
        $scope.filter.record_time_start = '';
        $scope.filter.record_time_end = '';
        var window_id = 0;
        //点击加载更多
        $scope.scoll = {};
        $scope.scoll.busy = false;
        $scope.scoll.nextpage = function () {
            if ($scope.scoll.busy)
                return;
            baison_app.api.toast({
                msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
            });
            $scope.scoll.busy = true;
            var param = {};
            param.is_pre = 1;
            param.store_code = $rootScope.current_shop.ShopCode;
            if ($scope.pandian_list.length > 0) {
                param.day = $scope.pandian_list[$scope.pandian_list.length - 1]['key'];
            }
            panDian.pandian_search_api(param).then(function (ret) {
                if (ret.data.status == 1) {
                    for (i in ret.data.data) {
                        $scope.pandian_list.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.scoll.busy = false;
                } else if (ret.data.status == -1) {
                    baison_app.api.toast({
                        msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
                    });
                    $scope.is_show = "";
                }
            });
        };
        //从服务器获取数据
        var search_api = function (filter) {
            panDian.pandian_search_api(filter).then(function (ret) {
                if (ret.data.status != 1) {
                    $scope.is_show = "";
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language[ret.data.code]
                    });
                    return;
                } else if (ret.data.status == 1) {
                    $scope.is_show = "true";
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.pandian_list = data;
                }
            }).catch(function (msg) {
                baison_app.api.toast({
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
                });
            });
        };
        search_api({
            store_code: $rootScope.current_shop.ShopCode
        });
        
        
        //获取小票信息
        var stock_getinfo = function (stock_detail) {
            var record = {};
            var configData = $api.getStorage('configData');
            var printData = configData.printData;
            var shop_addr = '';
            var shop_tel = '';
            var web_site = '';
            if (printData != undefined) {
                shop_addr = printData['addr'];
                shop_tel = printData['tel'];
                web_site = printData['web_site'];
            }

            record.check_code = '';
            record.check_time = timeStamp2String(0, 'datetime');
            record.stock_detail = stock_detail;
            record.shop_name = $rootScope.current_shop.ShopName;
            record.user_code = $rootScope.user.UserCode;
            record.user_name = $rootScope.user.UserName;
            record.brand_name = $rootScope.company_info.brand_name;
            record.shop_addr = shop_addr;
            record.shop_tel = shop_tel;
            record.web_site = $rootScope.company_info.website;
            //库存排序
            record.stock_detail.sort(function(a,b){
                if(a.category_code < b.category_code){
                    return -1;
                }else if(a.category_code == b.category_code){
                    if(a.sort_code < b.sort_code){
                        return -1;
                    }else if(a.sort_code == b.sort_code){
                        if(a.goods_code < b.goods_code){
                            return -1;
                        }else if(a.goods_code == b.goods_code){
                            return 0;
                        }else{
                            return 1;
                        }
                    }else{
                        return 1;
                    }
                }else{
                    return 1;
                }
            });
            return record;
        };

        //获取小票商品明细信息
        var get_goods_detail_infos = function(detail){
            var deferred = $q.defer();
            var promise = deferred.promise;
            detail.forEach(function(n,i){
                deferred[i] = $q.defer();
                promise[i] = deferred[i].promise;
                dbGetOne('select GoodsCode,SortCode,CategoryCode,weight,unit_name from PosGoods where GoodsCode="' + n.GoodsCode + '"').then(function(ret){
                    n.weight = ret.weight;
                    n.unit_name = ret.unit_name;
                    n.category_code = ret.CategoryCode;
                    n.goods_code = ret.GoodsCode;
                    n.sort_code = ret.SortCode;
                    deferred[i].resolve('success');
                });
               
            });
            return $q.all(promise);
        };

        //打印盘点数据
        $scope.to_print = function () {
            panDian.sku_search().then(function (ret) {
                get_goods_detail_infos(ret).then(function(){
                    var stock = stock_getinfo(ret);
                    Print.stock_print('', stock);
                });
                
            });

        };
        //查询
        $scope.search = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/cunhuo/pandian/pandian_select.html',
                disableAnimation: true,
                scope: $scope,
                //                closeByDocument: false
                trapFocus: false
            });
        };
        //重置按钮
        $scope.clear = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
        };
        //弹框处理================================
        $scope.pandian_select = function (filterData) {
            if (filterData.record_time_start == '' || filterData.record_time_end == '') {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME
                });
                return;
            }
            if (filterData.record_time_start > filterData.record_time_end) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME_LIMIT
                });
                return;
            }
            panDian.pandian_select(filterData).then(function (ret) {
                if (ret.data.status != 1) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language[ret.data.code]
                    });
                    return;
                } else if (ret.data.status == 1) {
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.pandian_list = data;
                }
            }).catch(function (err) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
            ngDialog.close(window_id);
        };
    }];

//盘点单据信息
var CunhuoPanDianDetailCtrl = ['$scope', '$routeParams', '$location', 'panDian', 'BaseGoods', '$rootScope', 'ngDialog','ThirdDev',
    function ($scope, $routeParams, $location, panDian, BaseGoods, $rootScope, ngDialog,ThirdDev) {
        $scope.curr = "pandian_list";
        $scope.is_lqx = ThirdDev.is_lqx();
        $scope.input_keywords = '';
        //弹窗:
        var window_id = 0;
        var filter = {};
        filter.record_code = $routeParams.record_code;
        //上传按钮和操作按钮
        $scope.is_submit = "";
        $scope.is_operate = "";
        panDian.pandian_list_detail_search_by_code(filter).then(function (ret) {
            if (ret.data.status == 1) {
                $scope.pandian_list_detail = ret.data.data;
                //表示的是lite
                if (!ThirdDev.is_lqx()) {  //$rootScope.purview['\/cunhuo\/pandianTask_list'].show == 1
                    //若盘点单状态是未确认，就让其修改
                    if ($scope.pandian_list_detail.record.is_sure == 0) {
                        $scope.is_submit = "true";
                        $scope.is_operate = "true";
                        //商品详细信息
                        goods_detail();
                        //搜索
                        $scope.search_goods = function (input_keywords) {
                            var key = new String(input_keywords);
                            if ('' == input_keywords || key.length < 3) {
                                baison_app.api.toast({
                                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                                    title: $rootScope.language.COMMON_TITLE_HINT,
                                    msg: $rootScope.language.TIPS_CUNHUO_NUM_NEED
                                });
                                return false;
                            }
                            panDian.sku_search_by_sku(input_keywords, $scope.pandian_list_detail.record.brand_code).then(function (ret) {
                                if (ret.length == 0) {
                                    baison_app.api.toast({
                                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                                        title: $rootScope.language.COMMON_TITLE_HINT,
                                        msg: $rootScope.language.TIPS_CUNHUO_SEARCH_GOODS
                                    });
                                    return false;
                                }
                                if (ret.length == 1) {
                                    $scope.sku = ret[0];
                                    $scope.sku.num;
                                    window_id = ngDialog.open({closeByDocument: false,
                                        template: './html/component/edit_num.html',
                                        disableAnimation: true,
                                        scope: $scope,
                                        //                        closeByDocument: false
                                        trapFocus: false,
                                        preCloseCallback: function () {
						                    $scope.close_keyboard();//关闭小键盘
						                }
                                    });
                                    //$scope.focus('input_num1');
                                    $scope.open_keyboard('sku.num');
                                } else {
                                    $scope.goods_select_data = ret;
                                    window_id = ngDialog.open({closeByDocument: false,
                                        template: './html/component/goods_select.html',
                                        disableAnimation: true,
                                        scope: $scope,
                                        //                        closeByDocument: false
                                        trapFocus: false
                                    });
                                }
                            });
                        };
                        //编辑操作
                        $scope.edit = function (sku) {
                            $scope.sku = sku;
                            //增加一个临时数量存储
                            $scope.sku.e_num = sku.num;
                            window_id = ngDialog.open({closeByDocument: false,
                                template: './html/component/edit.html',
                                disableAnimation: true,
                                scope: $scope,
                                //                closeByDocument: false
                                trapFocus: false,
                                preCloseCallback: function () {
				                    $scope.close_keyboard();//关闭小键盘
				                }
                            });
                            //$scope.focus('input_num2');
                            $scope.open_keyboard('sku.e_num');
                        };
                        //删除一条sku记录
                        $scope.del_sku = function (sku) {
                            window_id = ngDialog.open({closeByDocument: false,
                                trapFocus: false,
                                template: './html/component/deleteSku.html',
                                disableAnimation: true,
                                scope: $scope,
                                controller: ['$scope', function ($scope) {
                                        //确认删除商品
                                        $scope.deleteSku_submit = function () {
                                            ngDialog.close(window_id);
                                            $.each($scope.pandian_list_detail.record_detail, function (i, n) {
                                                if (n.sku == sku) {
                                                    $scope.pandian_list_detail.record_detail.splice(i, 1);
                                                    return false;
                                                }
                                            });
                                            refresh_record();
                                        };
                                        //取消删除商品
                                        $scope.deleteSku_close = function () {
                                            ngDialog.close(window_id);
                                        };
                                    }]
                            });
                        };
                    } else {
                        //盘点单状态是已确认（不修改明细，只读）
                        $.each($scope.pandian_list_detail.record_detail, function (i, n) {
                            $scope.pandian_list_detail.record_detail[i]['GoodsName'] = '';
                            if (n.goods_name == '' || n.goods_name == undefined) {
                                BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
                                    $scope.pandian_list_detail.record_detail[i]['GoodsName'] = ret.GoodsName;
                                });
                            } else {
                                $scope.pandian_list_detail.record_detail[i]['GoodsName'] = n.goods_name;
                            }
                        });
                        $scope.pandian_list_detail.record.is_upload = 0;
                    }
                } else {
                    //林清轩
                    $.each($scope.pandian_list_detail.record_detail, function (i, n) {
                        $scope.pandian_list_detail.record_detail[i]['GoodsName'] = '';
                        if (n.goods_name == '' || n.goods_name == undefined) {
                            BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
                                $scope.pandian_list_detail.record_detail[i]['GoodsName'] = ret.GoodsName;
                            });
                        } else {
                            $scope.pandian_list_detail.record_detail[i]['GoodsName'] = n.goods_name;
                        }
                    });
                    $scope.pandian_list_detail.record.is_upload = 0;
                }
            }
        });
        //私有方法+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        //商品明细
        var goods_detail = function () {
            //判断盘点单据是未确认状态:但是当前状态不是重盘造成的
            if($scope.pandian_list_detail.record.repeat_take_stock_num == null){
            	//盘点单据主表
            	panDian.take_stock_record_by_record_code($scope.pandian_list_detail.record.record_code).then(function(response){
            		if(response.length > 0){
            			$scope.pandian_list_detail.record.num = response[0].num;
						$scope.pandian_list_detail.record.money = response[0].money;
            		}
            	});
                //获取离线盘点单据明细
            	panDian.take_stock_get_wait_upload_detail($scope.pandian_list_detail.record.record_code).then(function(response){
	            	$scope.pandian_list_detail.record_detail = response;
	            	$.each($scope.pandian_list_detail.record_detail, function (i, n) {
		                $scope.pandian_list_detail.record_detail[i]['GoodsName'] = '';
		                if (n.goods_name == '' || n.goods_name == undefined) {
		                    BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
		                        $scope.pandian_list_detail.record_detail[i]['GoodsName'] = ret.GoodsName;
		                    });
		                } else {
		                    $scope.pandian_list_detail.record_detail[i]['GoodsName'] = n.goods_name;
		                }
		            });
	            }); 
	           $scope.pandian_list_detail.record.is_upload = 0;
            }else{
               //盘点单是未确认状态：且这个状态是重盘造成的
            	$.each($scope.pandian_list_detail.record_detail, function (i, n) {
	                $scope.pandian_list_detail.record_detail[i]['GoodsName'] = '';
	                if (n.goods_name == '' || n.goods_name == undefined) {
	                    BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
	                        $scope.pandian_list_detail.record_detail[i]['GoodsName'] = ret.GoodsName;
	                    });
	                } else {
	                    $scope.pandian_list_detail.record_detail[i]['GoodsName'] = n.goods_name;
	                }
	            });
	           $scope.pandian_list_detail.record.is_upload = 0;
            }                  
           
        };
        var goods_select_click_handler = function (sku) {
        	var flag = 0;
            $.each($scope.pandian_list_detail.record_detail,function(i,n){
            	if(n.sku == sku.SkuCode){
            		n.num = sku.num;
                    n.color = sku.color;
            		flag = 1;
            		return false;
            	}
            });
            if(flag == 0){
            	 $scope.pandian_list_detail.record_detail.push({
		            'record_code': filter.record_code,
		            'sku': sku.SkuCode,
		            'goods_name':sku.GoodsName,
                    'goods_name_zh_tw': sku.GoodsName_zh_tw,
                    'goods_name_en': sku.GoodsName_en,
		            'goods_code': sku.GoodsCode,
		            'color_code': sku.ColorCode,
		            'size_code': sku.SizeCode,
		            'price': new Number(sku.SkuPrice).toFixed(2),
		            'num': sku.num, //实盘数
                    'color':sku.color
		    	});    
            }
                
            //刷新整个盘点单
            refresh_record();
            $scope.input_keywords = '';
            ngDialog.close(window_id);
        };
        var refresh_record = function () {
            var num = 0;
            var money = 0;
            $.each($scope.pandian_list_detail.record_detail, function (index, n) {
                n.money = n.num * n.price;
                num = parseInt(num) + parseInt(n.num);
                money = parseFloat(money) + parseInt(n.num) * parseFloat(n.price);
            });
            $scope.pandian_list_detail.record.num = num;
            $scope.pandian_list_detail.record.money = money;
            //刷新添加商品的明细
            $.each($scope.pandian_list_detail.record_detail, function (i, n) {
	                $scope.pandian_list_detail.record_detail[i]['GoodsName'] = '';
	                if (n.goods_name == '' || n.goods_name == undefined) {
	                    BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
	                        $scope.pandian_list_detail.record_detail[i]['GoodsName'] = ret.GoodsName;
	                    });
	                } else {
	                    $scope.pandian_list_detail.record_detail[i]['GoodsName'] = n.goods_name;
	                }
	         });
        };

        //弹窗处理方法+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        //选择商品
        $scope.goods_select_click = function (sku) {
            $scope.sku = sku;
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/component/edit_num.html',
                disableAnimation: true,
                scope: $scope,
                //                closeByDocument: false
                trapFocus: false,
                preCloseCallback: function () {
                    $scope.close_keyboard();//关闭小键盘
                }
            });
            //$scope.focus('input_num1');
            //$scope.open_keyboard('sku.num');
            $scope.open_keyboard('sku.num');
        };
        //盘点单上传服务器
        $scope.record_upload = function (record, detail) {
            if (Object.keys(detail).length == 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.MSG_WITHOUT_SELECT_GOODS
                });
                return;
            }
            //上传盘点单明细
            panDian.add_take_stock_recordDetail_api(record.record_code, detail).then(function (ret) {
                if (ret.data.status == 1) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language[ret.data.code]
                    });
                    //上传的单据不能操作
                    $scope.is_submit = '';
                    //上传之后，操作按钮不显示
                    $scope.is_operate = " ";
                    //上传之后本地保存一份:盘点单主表和明细表信息,盘点单主表上传状态改成1
                    record.is_upload = 1;
	                panDian.save_record_detail(record, detail);                  
                    //上传成功之后
                    $location.path('/cunhuo/pandian_list');
                } else {
                    baison_app.api.toast({
                        msg: $rootScope.language[ret.data.code]
                    });
                }
            });
        };
        //关闭按钮
        $scope.come_back = function () {
            $location.path('/cunhuo/pandian_list');
        };
        //搜索商品选择数量
        $scope.save_num = function (sku) {
            var re = /^[1-9]+[0-9]*]*$/;
            if (sku.num == undefined) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EMPTY
                });
                return;
            } else if (sku.num < 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY1
                });
                return;
            } else if (!re.test(sku.num)) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                });
                return;
            }
            $scope.close_keyboard();//关闭小键盘
            goods_select_click_handler(sku);
            ngDialog.close(window_id);
        };
        //编辑:修改数量
        $scope.save_edit = function (sku) {
            var re = /^[1-9]+[0-9]*]*$/;
            if (sku.e_num < 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY1
                });
                return;
            } else if (!re.test(sku.e_num)) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                });
                return;
            }
            $scope.close_keyboard();//关闭小键盘
            sku.num = sku.e_num;
            refresh_record();
            ngDialog.close(window_id);
        };
        //编辑：取消
        $scope.clear = function () {
            refresh_record();
            ngDialog.close(window_id);
        };
    }];

//新增盘点单
var CunhuoPanDianAddCtrl = ['$scope', '$rootScope', '$location', 'timeStamp2String', 'yaoHuo','waitUpLoad','ngDialog',
    function ($scope, $rootScope, $location, timeStamp2String, yaoHuo,waitUpLoad,ngDialog) {
        baison_app.api.toast({
            buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
            title: $rootScope.language.COMMON_TITLE_HINT,
            msg: $rootScope.language.TIPS_ADD_PANDIAN_HINT
        });
        $scope.curr = "pandian_list";
        $scope.filter = {};
        $scope.filter.record_code = yaoHuo.create_fast_bill_sn('pandian');
        //盘点单号
        $scope.filter.record_time = timeStamp2String(0, 'datetime');
        //盘点日期
        $scope.filter.lastchanged = timeStamp2String(0, 'datetime');
        //更新时间
        $scope.filter.remark = '';
        //备注
        $scope.filter.store_code = $rootScope.current_shop.ShopCode;
        //$scope.filter.store_name = $rootScope.current_shop.ShopName;
        //店铺
        //盘点类型
        $scope.type = "";
        $scope.pytymp = {
            "code": "001",
            "value": $rootScope.language.TIPS_INVENTORY_MINGPAN //"明盘"
        };
        $scope.pytyap = {
            "code": "002",
            "value": $rootScope.language.TIPS_INVENTORY_ANPAN     //"盲盘"
        };
        ///////////////

        $scope.select = function (code) {
            $api.setStorage('type', code);
        };

        //生成盘点单
        $scope.add_pandian = function () {
            if ($api.getStorage('type') === undefined || $api.getStorage('type') == '') {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_PANDIAN
                });
                return false;
            }
            $rootScope.local_pandian = $scope.filter;
            var comp_firm = {};
            waitUpLoad.receipt_record_get_wait_upload_group_list().then(function (data) {
                
                if(data.length > 0){
                    
                    comp_firm = ngDialog.open({
                        closeByDocument: false,
                        template: './html/component/confirm.html',
                        disableAnimation: true,
                        trapFocus: false,
                        scope: $scope,
                        
                        controller: [function () {
                                //标题
                                $scope.title = $rootScope.language.COMMON_TITLE_HINT;
                                //内容
                                $scope.info = $rootScope.language.TIPS_PANDIAN_UPLOAD_OFFLINE_XP;
                            }]
                    });
                    
                    //确认
                    $scope.confirm = function () {
                        //弹出录入会员信息页面
                        $location.path('/setting/wait_upload');
                        ngDialog.close(comp_firm);
                    };
                    //取消
                    $scope.cancel = function () {
                        $location.path('/cunhuo/pandian_add_detail');
                        ngDialog.close(comp_firm);
                    };
                }else{
                    //把盘点类型以及时间保存
                    $location.path('/cunhuo/pandian_add_detail');
                }
                
            });
            //
            
            
        };
    }];

//新增盘点单详情
var CunhuoPanDianAddDetailCtrl = ['$scope', '$rootScope', '$location', 'ngDialog', 'panDian', 'BaseGoods', 'Print', 'timeStamp2String','ThirdDev','waitUpLoad',
    function ($scope, $rootScope, $location, ngDialog, panDian, BaseGoods, Print, timeStamp2String,ThirdDev,waitUpLoad) {
        $scope.is_lqx = ThirdDev.is_lqx();
        //权限判断是否是林清轩使用：0是林清轩使用
        if (ThirdDev.is_lqx()) {  //$rootScope.purview['\/cunhuo\/pandianTask_list'].show == 0
            $scope.curr = "pandian_list";
            $scope.record = $rootScope.local_pandian;
            $scope.record.num = 0;
            $scope.record.money = 0;
            //下一页不显示
            $scope.is_show_next = "";
            //预盈亏一直都显示
            $scope.is_show_yyk = "true";
            //未上传状态
            $scope.record.is_upload = 0;
            //未上传状态的单据显示上传
            $scope.is_submit = "true";
            //上传的单据不能再操作
            $scope.is_operate = "true";
            //单据上传之后就让其隐藏
            $scope.is_showSav = "true";
            $scope.input_keywords = '';
            var window_id = 0;
            $scope._detail = {};
            $scope.temp_detail=[];
            var temp_arr =[];
            //盘点类型
            var pdty = $api.getStorage('type');
            if (pdty == 001) {
                $scope.buttonPrint = 1;
                $scope.is_show = "true";
                $api.setStorage('type', '');
            } else {

                $scope.is_show = "";
                $api.setStorage('type', '');
            }
            //列出所有账面库存不等于0的商品
            var listAllSkus = function () {
	           	BaseGoods.get_skus_by_num_exists().then(function (response) {
	                  $.each(response,function(i,n){
		                  	 $scope._detail[n.SkuCode] = {
	                        'index': n.SkuCode, //下标
	                        'record_code': $scope.record.record_code,
	                        'sku': n.SkuCode,
	                        'goods_code': n.GoodsCode,
	                        'goods_name': n.GoodsName,
                            'goods_name_zh_tw': n.GoodsName_zh_tw,
                            'goods_name_en': n.GoodsName_en,
	                        'color_code': n.ColorCode,
	                        'size_code': n.SizeCode,
	                        'zhek': 1,
	                        'num': 0, //实盘数
	                        'price': new Number(n.SkuPrice).toFixed(2),
	                        'money': parseInt(n.num) * parseFloat(n.SkuPrice),
	                        'SkuNum': n.SkuNum,//账面数sku.SkuNum
                            'color': false
	                    };
	                    //刷新整个盘点单
	                    refresh_record();
                        temp_arr.push({'SkuCode':n.SkuCode});
                        $scope.temp_detail = temp_arr.concat();
                        $scope.temp_detail.reverse();
	                    $scope.input_keywords = '';
	                    ngDialog.close(window_id);
	                  });
	                  
	            });
	        };
	
	        listAllSkus();
            $scope.search_goods = function (keywords) {
                var key = new String(keywords);
                if ('' == keywords || key.length < 3) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_NUM_NEED
                    });
                    return false;
                }
                panDian.sku_search_by_sku(keywords).then(function (ret) {
                    if (ret.length == 0) {
                        baison_app.api.toast({
                            buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                            title: $rootScope.language.COMMON_TITLE_HINT,
                            msg: $rootScope.language.TIPS_CUNHUO_SEARCH_GOODS
                        });
                        return false;
                    }
                    if (ret.length == 1) {
                        $scope.sku = ret[0];
                        $scope.sku.num
                        window_id = ngDialog.open({closeByDocument: false,
                            template: './html/component/edit_num.html',
                            disableAnimation: true,
                            scope: $scope,
                            trapFocus: false,
                            preCloseCallback: function () {
			                    $scope.close_keyboard();//关闭小键盘
			                }
			                
                        });
                        //$scope.focus('input_num1');
                        $scope.open_keyboard('sku.num');
                          
                    } else {
                        $scope.goods_select_data = ret;
                        window_id = ngDialog.open({closeByDocument: false,
                            template: './html/component/goods_select.html',
                            disableAnimation: true,
                            scope: $scope,
                            //                        closeByDocument: false
                            trapFocus: false
                        });
                    }
                });
            };

            //盘点单保存本地
            $scope.save = function (record, detail) {
                if ($rootScope.purviewCheckChange('\/CunhuoPanDianAddDetailCtrl\/save')) {
                    return;
                }
                if (Object.keys(detail).length <= 0) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.MSG_WITHOUT_SELECT_GOODS
                    });
                    return;
                }
                $scope.close_keyboard();//关闭小键盘
                record.take_stock_type = pdty;
                panDian.save_record_detail(record, detail);
            };

            //盘点单上传服务器
            $scope.record_upload = function (record, detail) {
                
                if ($rootScope.purviewCheckChange('\/CunhuoPanDianAddDetailCtrl\/record_upload')) {
                    return;
                }
                if (Object.keys(detail).length == 0) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.MSG_WITHOUT_SELECT_GOODS
                    });
                    return;
                }
                
                var comp_firm = {};
                waitUpLoad.receipt_record_get_wait_upload_group_list().then(function (data) {
                    
                    if(data.length > 0){
                        baison_app.api.toast({
                            buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                            title: $rootScope.language.COMMON_TITLE_HINT,
                            msg: $rootScope.language.TIPS_UPLOAD_OFFLINE_XP_BEFORE_XP
                        });
                        $scope.save(record, detail);
                        $location.path('/setting/wait_upload');
                        ngDialog.close(comp_firm);
                    }else{
                        panDian.take_stock_record_add_detail_api(record, detail).then(function (ret) {
                            if (ret.data.status == 1) {
                                baison_app.api.toast({
                                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                                    title: $rootScope.language.COMMON_TITLE_HINT,
                                    msg: ret.data.message
                                });
                                $scope.is_submit = '';
                                //上传的单据不能操作
                                $scope.is_operate = "";
                                //上传之后保存按钮隐藏
                                $scope.is_showSav = "";
                                //上传之后不能重复上传、且更新本地盘点单据主表
                                panDian.update_stock_record(record.record_code);
                                $scope.record.relation_code = ret.data.data.take_stock_task_record_code;
                            } else {
                                baison_app.api.toast({
                                    msg: $rootScope.language[ret.data.code]
                                });
                            }
                        });
                    }
                    
                });
            };
            //编辑（修改数量）
            $scope.edit = function (sku) {
                $scope.sku = sku;
                $scope.sku.e_num = sku.num;
                //增加一个临时数量存储
                window_id = ngDialog.open({closeByDocument: false,
                    template: './html/component/edit.html',
                    disableAnimation: true,
                    scope: $scope,
                    //                closeByDocument: false
                    trapFocus: false,
                    preCloseCallback: function () {
		                    $scope.close_keyboard();//关闭小键盘
		                }
                });
                //$scope.focus('input_num2');
                $scope.open_keyboard('sku.e_num');
                //$scope.focus('input_num1', 1);
            };
            //删除
            $scope.del_sku = function (index,arrindex) {
                window_id = ngDialog.open({closeByDocument: false,
                    trapFocus: false,
                    template: './html/component/deleteSku.html',
                    disableAnimation: true,
                    scope: $scope,
                    controller: ['$scope', function ($scope) {
                            //确认删除商品
                            $scope.deleteSku_submit = function () {
                                ngDialog.close(window_id);
                                delete $scope._detail[index];
                                $scope.temp_detail.splice(arrindex, 1);
                                var lenindex =  temp_arr.length - 1 -(arrindex) ;
                                temp_arr.splice(lenindex, 1);
                                refresh_record();
                            };
                            //取消删除商品
                            $scope.deleteSku_close = function () {
                                ngDialog.close(window_id);
                            };
                        }]
                });
            };
            //预盈亏
            $scope.yyk = function (record, detail) {
                panDian.profit_and_loss_by_app(record, detail).then(function (ret) {
                    if (ret.data.status == 1) {
                        baison_app.api.toast({
                            buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                            title: $rootScope.language.COMMON_TITLE_HINT,
                            msg: ret.data.message
                        });
                        $location.path('/cunhuo/pandian_list');
                    }
                });
            };
            //私有方法======================================
            var goods_select_click_handler = function (sku) {
                //从本地获取账面数
                BaseGoods.getSkuNum_by_sku(sku.SkuCode).then(function (ret) {
                    sku.SkuNum = ret.SkuNum;
					if($scope._detail[sku.SkuCode] != undefined){
						$scope._detail[sku.SkuCode].num = sku.num*1;
					}else{
						$scope._detail[sku.SkuCode] = {
							'index': sku.SkuCode, //下标
							'record_code': $scope.record.record_code,
							'sku': sku.SkuCode,
							'goods_code': sku.GoodsCode,
							'goods_name': sku.GoodsName,
							'goods_name_zh_tw': sku.GoodsName_zh_tw,
							'goods_name_en': sku.GoodsName_en,
							'color_code': sku.ColorCode,
							'size_code': sku.SizeCode,
							'zhek': 1,
							'num': sku.num, //实盘数
							'color':sku.SkuNum == sku.num ?false:true,
							'price': new Number(sku.SkuPrice).toFixed(2),
							'money': parseInt(sku.num) * parseFloat(sku.SkuPrice),
							'SkuNum': sku.SkuNum //账面数sku.SkuNum
						};
						temp_arr.push({'SkuCode':sku.SkuCode});
						$scope.temp_detail = temp_arr.concat();
						$scope.temp_detail.reverse();
					}
                    //刷新整个盘点单
                    refresh_record();
                    $scope.input_keywords = '';
                    ngDialog.close(window_id);
                });

            };

            var refresh_record = function () {
                var num = 0;
                var money = 0;
                $.each($scope._detail, function (index, n) {
                    n.color = (n.SkuNum == n.num) ?false:true;
                    n.money = n.num * n.price;
                    num = parseInt(num) + parseInt(n.num);
                    money = parseFloat(money) + parseInt(n.num) * parseFloat(n.price);
                });
                $scope.record.num = num;
                $scope.record.money = money;
            };
            //弹框处理======================================
            //选择商品
            $scope.goods_select_click = function (sku) {
                $scope.sku = sku;
                window_id = ngDialog.open({closeByDocument: false,
                    template: './html/component/edit_num.html',
                    disableAnimation: true,
                    scope: $scope,
                    //                closeByDocument: false
                    trapFocus: false,
                    preCloseCallback: function () {
	                    $scope.close_keyboard();//关闭小键盘
	                }
                    
                });
                //$scope.focus('input_num1');
                $scope.open_keyboard('sku.num');
            };
            //选择商品填写数量
            $scope.save_num = function (sku) {
                var re = /^\d*$/;
                if (sku.num == undefined) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_NUM_EMPTY
                    });
                    return;
                }
                 if (sku.num < 0) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY1
                    });
                    return;
                } 
                if (!re.test(sku.num)) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                    });
                    return;
                }
                $scope.close_keyboard();//关闭小键盘
                //获取商品库存账面数
                goods_select_click_handler(sku);
                ngDialog.close(window_id);
                
            };
            //编辑修改数量
            $scope.save_edit = function (sku) {
                var re = /^\d*$/;
                if (sku.e_num < 0) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY1
                    });
                    return;
                } else if (!re.test(sku.e_num)) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                    });
                    return;
                }
                $scope.close_keyboard();//关闭小键盘
                sku.num = sku.e_num;
                refresh_record();
                ngDialog.close(window_id);
            };
            $scope.clear = function () {
                refresh_record();
                ngDialog.close(window_id);
            };

        } else {
            $scope.curr = "pandian_list";
            $scope.record = $rootScope.local_pandian;
            $scope.record.num = 0;
            $scope.record.money = 0;
             //上传状态
            $scope.record.is_upload = 0;
            //账面数显示
            $scope.is_show = "true";
            //上传按钮
            $scope.is_submit = "true";
            //保存按钮，单据上传之后就隐藏
            $scope.is_showSav = "true";
            //预盈亏一直都不显示
            $scope.is_show_yyk = "";
            //编辑按钮
            $scope.is_operate = "true";
            $scope.input_keywords = '';
            var window_id = 0;
            $scope._detail = {};
            $scope.temp_detail=[];
            var temp_arr =[];
            //判断是否是全盘
            if ($scope.record.stock_type == 0) {
                //判断是否是自动录入商品,0:手动录入商品,1：自动录入
                if ($scope.record.status == 1) {
                    //全盘
                    var length = 100;
                    //点击搜索按钮
                    var listAllSkus = function () {
                        $scope.is_show_next = "true";
                        $scope.is_submit = "";
                        BaseGoods.getAllReturnsSkus(0, length, $scope.record.brand_code).then(function (ret) {
                            goods_select_click_handler(ret);
                        });
                    };
                    listAllSkus();
                    //下一页
                    $scope.next_page = function () {
                        BaseGoods.getAllReturnsSkus(length, 100, $scope.record.brand_code).then(function (ret) {
                            length = length + ret.length;
                            if (ret.length > 0) {
                                goods_select_click_handler(ret);
                            } else {
                                baison_app.api.toast({
                                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE,
                                });
                                //下一页不显示
                                $scope.is_show_next = "";
                                $scope.is_submit = "true";
                            }
                        });
                    };
                }

            }

            $scope.search_goods = function (keywords) {
                var key = new String(keywords);
                if ('' == keywords || key.length < 3) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_NUM_NEED
                    });
                    return false;
                }
                //判断是全盘还是商品级的盘点,1:商品级盘点
                if ($scope.record.stock_type == 1) {
					//status,0：手动录入
                    if ($scope.record.status == 0) {
                        //商品级、手动录入(判断是否有品牌限制：$scope.record.brand_code,在模型层判断)
                        panDian.sku_search_by_sku(keywords, $scope.record.brand_code).then(function (ret) {
                            if (ret.length == 0) {
                                baison_app.api.toast({
                                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                                    title: $rootScope.language.COMMON_TITLE_HINT,
                                    msg: $rootScope.language.TIPS_CUNHUO_SEARCH_GOODS
                                });
                                return false;
                            }
                            if (ret.length == 1) {
                                $scope.sku = ret[0];
                                $scope.sku.num;
                                window_id = ngDialog.open({closeByDocument: false,
                                    template: './html/component/edit_num.html',
                                    disableAnimation: true,
                                    scope: $scope,
                                    //                        closeByDocument: false
                                    trapFocus: false,
                                    preCloseCallback: function () {
					                    $scope.close_keyboard();//关闭小键盘
					                }
                                });
                                //$scope.focus('input_num1');
                                $scope.open_keyboard('sku.num');
                            } else {
                                $scope.goods_select_data = ret;
                                window_id = ngDialog.open({closeByDocument: false,
                                    template: './html/component/goods_select.html',
                                    disableAnimation: true,
                                    scope: $scope,
                                    //                        closeByDocument: false
                                    trapFocus: false
                                });
                            }
                        });
                    }

                } else if ($scope.record.stock_type == 0) {
                   //stock_type:0 全盘
                    //自动录入商品（全盘）和手动录入商品（全盘）都可以搜索,0:手动录入商品:(判断是否有品牌限制：$scope.record.brand_code,在模型层判断)
                    if ($scope.record.status == 0 || $scope.record.status == 1) {
                        panDian.sku_search_by_sku(keywords, $scope.record.brand_code).then(function (ret) {
                            if (ret.length == 0) {
                                baison_app.api.toast({
                                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                                    title: $rootScope.language.COMMON_TITLE_HINT,
                                    msg: $rootScope.language.TIPS_CUNHUO_SEARCH_GOODS
                                });
                                return false;
                            }
                            if (ret.length == 1) {
                                $scope.sku = ret[0];
                                $scope.sku.num;
                                window_id = ngDialog.open({closeByDocument: false,
                                    template: './html/component/edit_num.html',
                                    disableAnimation: true,
                                    scope: $scope,
                                    //                        closeByDocument: false
                                    trapFocus: false,
                                    preCloseCallback: function () {
					                    $scope.close_keyboard();//关闭小键盘
					                }
                                });
                                //$scope.focus('input_num1');
                                $scope.open_keyboard('sku.num');
                            } else {
                                $scope.goods_select_data = ret;
                                window_id = ngDialog.open({closeByDocument: false,
                                    template: './html/component/goods_select.html',
                                    disableAnimation: true,
                                    scope: $scope,
                                    //                        closeByDocument: false
                                    trapFocus: false
                                });
                            }
                        });
                    }
                }
            };
            //盘点单上传服务器
            $scope.record_upload = function (record, detail) {
                if (Object.keys(detail).length == 0) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.MSG_WITHOUT_SELECT_GOODS
                    });
                    return;
                }
                //上传盘点单明细
                panDian.add_take_stock_recordDetail_api(record.record_code, detail).then(function (ret) {
                   
                    if (ret.data.status == 1) {
                        baison_app.api.toast({
                            buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                            title: $rootScope.language.COMMON_TITLE_HINT,
                            msg: $rootScope.language[ret.data.code]
                        });
                        //上传的单据不能操作
                        $scope.is_submit = '';
                        //上传之后，操作按钮不显示
                        $scope.is_operate = " ";
                        //上传之后保存按钮隐藏
                        $scope.is_showSav =" ";
                         //上传之后本地保存一份:盘点单主表和明细表信息,盘点单主表上传状态改成1
                        record.is_upload = 1;
                        //record.take_stock_type = pdty;
	                    panDian.save_record_detail(record, detail);
                        //如果成功就跳转到
                        $location.path('/cunhuo/pandian_list');
                    } else {
                        baison_app.api.toast({
                            msg: $rootScope.language[ret.data.code]
                        });
                    }
                });
            };
            //保存盘点单在本地
            $scope.save = function(record,detail){
            	if (Object.keys(detail).length <= 0) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.MSG_WITHOUT_SELECT_GOODS
                    });
                    return;
                }
                $scope.close_keyboard();//关闭小键盘
                record.take_stock_type = pdty;
                panDian.save_record_detail(record, detail);
            };
            //编辑（修改数量）
            $scope.edit = function (sku) {
                $scope.sku = sku;
                $scope.sku.e_num = sku.num;
                //增加一个临时数量存储
                window_id = ngDialog.open({closeByDocument: false,
                    template: './html/component/edit.html',
                    disableAnimation: true,
                    scope: $scope,
                    //                closeByDocument: false
                    trapFocus: false,
                    preCloseCallback: function () {
	                    $scope.close_keyboard();//关闭小键盘
	                }
                });
                //$scope.focus('input_num2');
                $scope.open_keyboard('sku.e_num');
            };
            //删除
            $scope.del_sku = function (index,arrindex) {
                window_id = ngDialog.open({closeByDocument: false,
                    trapFocus: false,
                    template: './html/component/deleteSku.html',
                    disableAnimation: true,
                    scope: $scope,
                    controller: ['$scope', function ($scope) {
                            //确认删除商品
                            $scope.deleteSku_submit = function () {
                                ngDialog.close(window_id);
                                delete $scope._detail[index];
                                $scope.temp_detail.splice(arrindex, 1);
                                var lenindex =  temp_arr.length - 1 -(arrindex) ;
                                temp_arr.splice(lenindex, 1);
                                refresh_record();
                            };
                            //取消删除商品
                            $scope.deleteSku_close = function () {
                                ngDialog.close(window_id);
                            };
                        }]
                });
            };

            //私有方法======================================
            var goods_select_click_handler = function (skus) {
     			var num = '';
                $.each(skus, function (i, n) {
					if($scope._detail[n.SkuCode] != undefined ){
						$scope._detail[n.SkuCode].num = n.num;
					}else{
						$scope._detail[n.SkuCode] = {
							'index': n.SkuCode, //下标
							'record_code': $scope.record.record_code,
							'sku': n.SkuCode,
							'goods_code': n.GoodsCode,
							'goods_name': n.GoodsName,
							'goods_name_zh_tw': n.GoodsName_zh_tw,
							'goods_name_en': n.GoodsName_en,
							'color_code': n.ColorCode,
							'size_code': n.SizeCode,
							'zhek': 1,
							'num': n.num, //实盘数
							'color':n.SkuNum == n.num ? false:true,
							'price': new Number(n.SkuPrice).toFixed(2),
							'money': parseInt(n.SkuNum) * parseFloat(n.SkuPrice),
							'SkuNum': n.SkuNum //账面数sku.SkuNum
						};
						temp_arr.push({'SkuCode':n.SkuCode});
						$scope.temp_detail = temp_arr.concat();
						$scope.temp_detail.reverse();
					}
                    
                });
                //刷新整个盘点单
                refresh_record();
                $scope.input_keywords = '';
                ngDialog.close(window_id);
            };


            var refresh_record = function () {
                var num = 0;
                var money = 0;
                $.each($scope._detail, function (index, n) {
                    console.log(n);
                	if(n.num == '' || n.num == undefined){
                		n.num = 0;
                	}
                    
                    n.money = n.num * n.price;
                    num = parseInt(num) + parseInt(n.num);
                    money = parseFloat(money) + parseInt(n.num) * parseFloat(n.price);
                });
                $scope.record.num = num;
                $scope.record.money = money;
            };
            //弹框处理======================================
            //商品级的选择商品
            $scope.goods_select_click = function (sku) {
                //盘点类型是全盘
                if ($scope.record.stock_type == 0) {
                    $scope.sku = sku;
                    window_id = ngDialog.open({closeByDocument: false,
                        template: './html/component/edit_num.html',
                        disableAnimation: true,
                        scope: $scope,
                        //                closeByDocument: false
                        trapFocus: false,
                        preCloseCallback: function () {
		                    $scope.close_keyboard();//关闭小键盘
		                }
                    });
                    //$scope.focus('input_num1');
                    $scope.open_keyboard('sku.num');
                }
                //根据货号获取所有sku,商品级盘点
                if ($scope.record.stock_type == 1) {
                    panDian.get_skus_by_goods_code(sku.GoodsCode).then(function (response) {
                        goods_select_click_handler(response);
                    });
                }
            };
            //编辑修改数量
            $scope.save_edit = function (sku) {
                var re = /^[1-9]+[0-9]*]*$/;
                if (sku.e_num < 0) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY1
                    });
                    return;
                } else if (!re.test(sku.e_num)) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                    });
                    return;
                }
                sku.num = sku.e_num;
                $scope.close_keyboard();//关闭小键盘
                refresh_record();
                ngDialog.close(window_id);
            };
            $scope.clear = function () {
                refresh_record();
                ngDialog.close(window_id);
            };
            //选择商品填写数量(全盘手动录入)
            $scope.save_num = function (sku) {
                var re = /^[1-9]+[0-9]*]*$/;
                if (sku.num == undefined) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_NUM_EMPTY
                    });
                    return;
                } else if (sku.num < 0) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_NUM_EARLY1
                    });
                    return;
                } else if (!re.test(sku.num)) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIPS_CUNHUO_NUM_TYPE
                    });
                    return;
                }
                BaseGoods.getSkuNum_by_sku(sku.SkuCode).then(function (ret) {
                    sku.SkuNum = ret.SkuNum;
                    $scope._detail[sku.SkuCode] = {
                        'index': sku.SkuCode, //下标
                        'record_code': $scope.record.record_code,
                        'sku': sku.SkuCode,
                        'goods_code': sku.GoodsCode,
                        'goods_name': sku.GoodsName,
                        'goods_name_zh_tw': sku.GoodsName_zh_tw,
                        'goods_name_en': sku.GoodsName_en,
                        'color_code': sku.ColorCode,
                        'size_code': sku.SizeCode,
                        'zhek': 1,
                        'num': sku.num, //实盘数
                        'price': new Number(sku.SkuPrice).toFixed(2),
                        'money': parseInt(sku.num) * parseFloat(sku.SkuPrice),
                        'SkuNum': sku.SkuNum, //账面数sku.SkuNum
                        'color':sku.SkuNum == sku.num ? false:true
                    };
                    //刷新整个盘点单
                    refresh_record();
                    temp_arr.push({'SkuCode':sku.SkuCode});
                    $scope.temp_detail = temp_arr.concat();
                    $scope.temp_detail.reverse();
                    $scope.input_keywords = '';
                    ngDialog.close(window_id);
                });
                $scope.close_keyboard();//关闭小键盘
                ngDialog.close(window_id);
            };

        }

    }];

//调整单
var CunhuoAdjustListCtrl = ['$scope', '$rootScope', 'ngDialog', 'adjust',
    function ($scope, $rootScope, ngDialog, adjust) {
        $scope.curr = "adjust_list";
        var window_id = 0;
        //查询条件
        $scope.filter = {};
        $scope.filter.record_code = '';
        $scope.filter.record_time_start = '';
        $scope.filter.record_time_end = '';
        //查找
        $scope.search = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/cunhuo/adjust/adjust_select.html',
                disableAnimation: true,
                scope: $scope,
                //                closeByDocument: false
                trapFocus: false
            });
        };
        //重置
        $scope.reset = function () {
            $scope.filter.record_code = '';
            $scope.filter.record_time_start = '';
            $scope.filter.record_time_end = '';
        };
        //从服务器获取数据
        var search_api = function (filter) {
            adjust.adjust_search_api(filter).then(function (ret) {
                if (ret.data.status != 1) {
                    $scope.is_show = "";
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language[ret.data.code]
                    });
                    return;
                } else if (ret.data.status == 1) {
                    $scope.is_show = "true";
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.adjust_list = data;
                }
            }).catch(function (msg) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
        };
        search_api({
            store_code: $rootScope.current_shop.ShopCode
        });
        //点击加载更多
        $scope.scoll = {};
        $scope.scoll.busy = false;
        $scope.scoll.nextpage = function () {
            if ($scope.scoll.busy)
                return;
            baison_app.api.toast({
                msg: $rootScope.language.COMMON_LOADING
            });
            $scope.scoll.busy = true;
            var param = {};
            param.is_pre = 1;
            param.store_code = $rootScope.current_shop.ShopCode;
            if ($scope.adjust_list.length > 0) {
                param.day = $scope.adjust_list[$scope.adjust_list.length - 1]['key'];
            }
            adjust.adjust_search_api(param).then(function (ret) {
                if (ret.data.status == 1) {
                    for (i in ret.data.data) {
                        $scope.adjust_list.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.scoll.busy = false;
                } else if (ret.data.status == -1) {
                    baison_app.api.toast({
                        msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
                    });
                    $scope.is_show = "";
                }
            });
        };
        //弹窗处理==============================
        $scope.adjust_select = function (filterData) {
            if (filterData.record_time_start == '' || filterData.record_time_end == '') {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME
                });
                return;
            }
            if (filterData.record_time_start > filterData.record_time_end) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME_LIMIT
                });
                return;
            }
            adjust.adjust_select(filterData).then(function (ret) {
                if (ret.data.status != 1) {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language[ret.data.code]
                    });
                    return;
                } else if (ret.data.status == 1) {
                    var data = [];
                    for (i in ret.data.data) {
                        data.push({
                            key: i,
                            value: ret.data.data[i]
                        });
                    }
                    $scope.adjust_list = data;
                }
            }).catch(function (err) {
                baison_app.api.toast({
                    msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
                });
            });
            ngDialog.close(window_id);
        };
    }];

//调整单据明细
var CunhuoAdjustDetailCtrl = ['$scope', '$rootScope', 'Print', '$location', '$routeParams', 'adjust', 'BaseGoods',
    function ($scope, $rootScope, Print, $location, $routeParams, adjust, BaseGoods) {
        $scope.curr = "adjust_list";
        var filter = {};
        filter.record_code = $routeParams.record_code;
        adjust.adjust_list_detail_search_by_code(filter).then(function (ret) {
            $scope.adjust_list_detail = ret.data.data;
            $.each($scope.adjust_list_detail.record_detail, function (i, n) {
                $scope.adjust_list_detail.record_detail[i]['GoodsName'] = '';
                //林清轩本地查找
                if (n.goods_name == '' || n.goods_name == undefined) {
                    BaseGoods.get_GoodsName_by_sku(n.sku).then(function (ret) {
                        $scope.adjust_list_detail.record_detail[i]['GoodsName'] = ret.GoodsName;
                    });
                } else {
                    $scope.adjust_list_detail.record_detail[i]['GoodsName'] = n.goods_name;
                }
            });
        });
        //返回按钮
        $scope.come_back = function () {
            $location.path('/cunhuo/adjust_list');
        };
        //added by lqx maowei on 20170112 盘点差异详细打印
        $scope.to_print_pandianchayidetail = function () {
            adjust.adjust_list_detail_search_by_code(filter).then(function (ret) {
                $scope.adjust_list_detail = ret.data.data;
                var pandianchayidetail = ret.data.data;
                    Print.pandianchayidetail_print('', pandianchayidetail);
            });
        };
    }];

//零售销货单
var FinishedSaleCtrl = ['$scope', '$rootScope', 'finishedReceipt', 'timeStamp2String',
    function ($scope, $rootScope, finishedReceipt, timeStamp2String) {
        var nowTime = new Date();
        var nowDay = timeStamp2String(nowTime, 'date');
        $scope.curr = "sale_list";
        $scope.listShow = 0;
        $scope.listShow = 0;
        $scope.receiptList = [];

        $scope.get_last_time = function () {
            finishedReceipt.get_more_sale_list($scope.nextTime).then(function (data) {
                if (data.data.status == "-1") {
                    $scope.nextTime = 0;
                    return;
                } else {
                    $scope.nextTime = data.data[0].date;
                    $scope.nextpage();
                }
            });
        };
        $scope.nextpage = function () {
            if ($scope.nextTime == 0) {
                baison_app.api.toast({msg: $rootScope.language.TIPS_CUNHUO_MESSAGE});
                return;
            }
            finishedReceipt.get_sale_list($scope.nextTime).then(function (ret) {
                if (ret.data.data.data.length != "0") {
                    $scope.receiptList.push({key: $scope.nextTime, value: ret.data.data.data});
                    finishedReceipt.get_more_sale_list($scope.nextTime).then(function (data) {
                        if (data.data.status == "-1") {
                            $scope.nextTime = '0';
                            return;
                        } else {
                            $scope.nextTime = data.data[0].date;
                        }
                    });
                } else {
                    $scope.get_last_time();
                }
            });
        };

        finishedReceipt.get_sale_list(nowDay).then(function (ret) {
            if (ret.data.data.data.length == "0") {
                $scope.nextTime = nowDay;
                $scope.nextpage();
                return;
            }
//                                for (var i in ret.data.data.data) { 
            $scope.receiptList.push({key: nowDay, value: ret.data.data.data});
//                                }
            finishedReceipt.get_more_sale_list(nowDay).then(function (data) {
                if (data.data.status == '-1') {
                    $scope.nextTime = 0;
                } else {
                    $scope.nextTime = data.data[0].date;
                }
            });
        });
        $scope.getDetail = function (data) {
            $scope.receiptListDetails = data;
            $scope.receiptListDetails.rq1 = $scope.receiptListDetails.rq * 1000;
            $scope.receiptListDetails.qrrq1 = $scope.receiptListDetails.qrrq * 1000;
            $scope.listShow = 1;
            finishedReceipt.get_sale_details(data.djbh).then(function (ret) {
                $scope.saleDetails = ret.data.data.data;
            }).then(function (success) {
                finishedReceipt.get_sale_check_type(data.djbh).then(function (ret) {
                    $scope.checkType = ret.data.data.data;
//                    console.log($scope.checkType)
                });
            });
            $scope.detailShow = 1;
        };

//        $scope.checkDetails = function () {
//            $scope.detailShow = 2;
//            finishedReceipt.get_sale_check_type($scope.receiptListDetails.djbh).then(function (ret) {
//                $scope.checkType = ret.data.data.data;
//            });
//        };
//        $scope.checkDetails();
//        $scope.goodsDetails = function () {
//            $scope.detailShow = 1;
//        };
//        $scope.additionalInfo = function () {
//            $scope.detailShow = 3;
//        };
        $scope.close_detail = function () {
            $scope.listShow = 0;
        }
    }];

//零售退货单
var FinishedReturnCtrl = ['$scope', '$rootScope', 'finishedReceipt', 'timeStamp2String',
    function ($scope, $rootScope, finishedReceipt, timeStamp2String) {
        var nowTime = new Date();
        var nowDay = timeStamp2String(nowTime, 'date');
        $scope.curr = "return_list";
        $scope.listShow = 0;
        $scope.receiptList = [];

        $scope.get_last_time = function () {
            finishedReceipt.get_more_return_list($scope.nextTime).then(function (data) {
                if (data.data.status == "-1") {
                    $scope.nextTime = 0;
                    return;
                } else {
                    $scope.nextTime = data.data[0].date;
                    $scope.nextpage();
                }
            });
        };

        $scope.nextpage = function () {
            if ($scope.nextTime == 0) {
                baison_app.api.toast({msg: $rootScope.language.TIPS_CUNHUO_MESSAGE});
                return;
            }
            finishedReceipt.get_return_list($scope.nextTime).then(function (ret) {
                if (ret.data.data.data.length != "0") {
                    $scope.receiptList.push({key: $scope.nextTime, value: ret.data.data.data});
                    finishedReceipt.get_more_return_list($scope.nextTime).then(function (data) {
                        if (data.data.status == "-1") {
                            $scope.nextTime = 0;
                            return;
                        } else {
                            $scope.nextTime = data.data[0].date;
                        }
                    });
                } else {
                    $scope.get_last_time();
                }
            });
        };

        finishedReceipt.get_return_list(nowDay).then(function (ret) {
            if (ret.data.data.data.length == "0") {
                $scope.nextTime = nowDay;
                $scope.nextpage();
                return;
            }
//                                for (var i in ret.data.data.data) { 
            $scope.receiptList.push({key: nowDay, value: ret.data.data.data});
//                                }
            finishedReceipt.get_more_return_list(nowDay).then(function (data) {
                if (data.data.status == '-1') {
                    $scope.nextTime = 0;
                } else {
                    $scope.nextTime = data.data[0].date;
                }
            });
        });
        $scope.getDetail = function (data) {
            $scope.receiptListDetails = data;
            $scope.receiptListDetails.rq1 = $scope.receiptListDetails.rq * 1000;
            $scope.receiptListDetails.qrrq1 = $scope.receiptListDetails.qrrq * 1000;
            $scope.listShow = 1;
            finishedReceipt.get_return_details(data.djbh).then(function (ret) {
                $scope.returnDetails = ret.data.data.data;
            }).then(function (success) {
                finishedReceipt.get_return_check_type(data.djbh).then(function (ret) {
                    $scope.checkType = ret.data.data.data;
                });
            });
            $scope.detailShow = 1;
        };
//        $scope.checkDetails = function () {
//            $scope.detailShow = 2;
//            finishedReceipt.get_return_check_type($scope.receiptListDetails.djbh).then(function (ret) {
//
//                baison_app.api.alert({msg: ret, title: 111})
//
//                $scope.checkType = ret.data.data.data;
//            });
//        };
        $scope.goodsDetails = function () {
            $scope.detailShow = 1;
        };
        $scope.additionalInfo = function () {
            $scope.detailShow = 3;
        };
        $scope.close_detail = function () {
            $scope.listShow = 0;
        };
    }];
CunhuoNavCtrl.$injector = ['$scope', '$rootScope'];
InvoicingNavCtrl.$injector = ['$scope', '$rootScope'];
CunhuoPeihuoListCtrl.$injector = ['$scope', '$location', '$rootScope', 'ngDialog', 'dbSelect', 'timeStamp2String', 'yaoHuo', 'PosUser', 'ShopSetCheck'];
CunhuoPeihuoDetailCtrl.$injector = ['$scope', '$location', '$routeParams', 'yaoHuo', 'BaseGoods', 'timeStamp2String'];
CunhuoPeihuoAddCtrl.$injector = ['$scope', '$rootScope', '$location', '$routeParams', 'dbSelect', 'yaoHuo', 'timeStamp2String', 'PosUser','ThirdDev'];
CunhuoPeihuoAddAdviseCtrl.$injector = ['$scope', '$rootScope', '$location', '$routeParams', 'dbSelect', 'yaoHuo', 'timeStamp2String', 'PosUser','ThirdDev'];
CunhuoPeihuoAddDetailCtrl.$injector = ['$scope', '$location', '$rootScope', 'ngDialog', 'yaoHuo'];
CunhuoPeihuoAddAdviseDetailCtrl.$injector = ['$scope', '$location', '$rootScope', 'ngDialog', 'yaoHuo', 'BaseGoods'];
CunhuoRukuListCtrl.$injector = ['$scope', '$rootScope', 'ngDialog', 'ruKu','ThirdDev'];
CunhuoRukuDetailCtrl.$injector = ['$scope', '$rootScope', '$location', '$routeParams', 'ngDialog', 'ruKu', 'BaseGoods','ThirdDev'];
CunhuoTuikuListCtrl.$injector = ['$scope', '$rootScope', 'ngDialog', 'tuiKu'];
CunhuoTuikuDetailCtrl.$injector = ['$scope', '$rootScope', '$location', '$routeParams', 'tuiKu', 'BaseGoods','ThirdDev'];
CunhuoTuikuAddCtrl.$injector = ['$scope', '$rootScope', '$location', 'ngDialog', 'timeStamp2String', 'PosUser', 'tuiKu', 'yaoHuo','ThirdDev'];
CunhuoTuikuAddAllCtrl.$injector = ['$scope', '$rootScope', '$location', 'ngDialog', 'timeStamp2String', 'PosUser', 'tuiKu', 'yaoHuo'];
CunhuoTuikuAddAllDetailCtrl.$injector = ['$scope', '$rootScope', '$location', 'ngDialog', 'tuiKu', 'BaseGoods'];
CunhuoTuikuAddDetailCtrl.$injector = ['$scope', '$rootScope', '$location', 'ngDialog', 'tuiKu'];
CunhuoChukuListCtrl.$injector = ['$scope', '$rootScope', '$location', 'ngDialog', 'chuku'];
CunhuoChukuDetailCtrl.$injector = ['$scope', '$rootScope', '$location', 'ngDialog', 'chuku', '$routeParams'];
CunhuoDiaoboListCtrl.$injector = ['$scope', '$rootScope', 'ngDialog', 'diaoBo'];
CunhuoDiaoboDetailCtrl.$injector = ['$scope', '$location', '$routeParams', 'diaoBo', 'BaseGoods', '$rootScope'];
CunhuoDiaoboAddCtrl.$injector = ['$scope', '$rootScope', '$location', 'timeStamp2String', 'PosUser', 'yaoHuo', 'diaoBo', 'ShopGetFriend','ThirdDev'];
CunhuoDiaoboAddDetailCtrl.$injector = ['$scope', '$rootScope', 'ngDialog', '$location', 'timeStamp2String', 'yaoHuo', 'diaoBo'];
CunhuoDiaoChuListCtrl.$injector = ['$scope', '$rootScope', 'ngDialog', 'diaoChu','ThirdDev'];
CunhuoDiaoChuDetailCtrl.$injector = ['$scope', '$location', '$routeParams', 'diaoChu', 'BaseGoods', '$rootScope','ThirdDev'];
CunhuoDiaoRuListCtrl.$injector = ['$scope', '$rootScope', 'ngDialog', 'diaoRu','ThirdDev'];
CunhuoDiaoRuDetailCtrl.$injector = ['$scope', '$rootScope', '$routeParams', '$location', 'diaoRu', 'BaseGoods','ThirdDev'];
CunhuoPanDianTaskListCtrl.$injector = ['$scope', '$rootScope', 'ngDialog', 'panDian'];
CunhuoPanDianTaskDetailCtrl.$injector = ['$scope', '$routeParams', '$location', '$rootScope', 'ngDialog', 'panDian', 'yaoHuo', 'timeStamp2String', 'BaseGoods'];
CunhuoPanDianListCtrl.$injector = ['$q', '$scope', '$rootScope', 'ngDialog', 'panDian','timeStamp2String','Print','dbGetOne'];
CunhuoPanDianDetailCtrl.$injector = ['$scope', '$routeParams', '$location', 'panDian', 'BaseGoods', '$rootScope', 'ngDialog','ThirdDev'];
CunhuoPanDianAddCtrl.$injector = ['$scope', '$rootScope', '$location', 'timeStamp2String', 'yaoHuo','waitUpLoad','ngDialog'];
CunhuoPanDianAddDetailCtrl.$injector = ['$scope', '$rootScope', '$location', 'ngDialog', 'panDian', 'BaseGoods', 'Print', 'timeStamp2String','ThirdDev','waitUpLoad'];
CunhuoAdjustListCtrl.$injector = ['$scope', '$rootScope', 'ngDialog', 'adjust'];
CunhuoAdjustDetailCtrl.$injector = ['$scope', '$rootScope', '$location', '$routeParams', 'adjust', 'BaseGoods'];

FinishedSaleCtrl.$injector = ['$scope', '$rootScope', 'finishedReceipt', 'timeStamp2String'];
FinishedReturnCtrl.$injector = ['$scope', '$rootScope', 'finishedReceipt', 'timeStamp2String'];